Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!apple!metaphor!dattatri From: dattatri@metaphor.Metaphor.COM (Dattatri) Newsgroups: comp.lang.c++ Subject: Static member Initialization Keywords: Questions? Message-ID: <2104@metaphor.Metaphor.COM> Date: 4 Mar 91 22:19:33 GMT Organization: Metaphor Computer Systems, Mountain View, CA Lines: 30 Here is a piece of code. class st { static int x; int y; public: static display() { printf("x = %d\n", x); } static increment() { x++; } }; main() { st::display(); // 1 st s; int st::x = 20; st::display(); // 2 int st::x = 30; st::increment(); s.display(); } When I compile and run this code, what should be the value of 'x' at (1)? At (1) is 'x' already initialized? With the g++, (1) prints x=30. What is the effect of st::x=20? Thanks in advance Kayshav -- dattatri@metaphor.com