Interview Questions

171. find a bug in following code .......

Microsoft Interview Questions and Answers


(Continued from previous question...)

171. find a bug in following code .......

Question:
find a bug in following code :
class A
{
public:
static int i;
void print()
{
cout<< i << endl ;
}
};

int main()
{
A a;
a.print();
}



maybe an answer1:


1 bug:
static is a declaration not a definition, because you can not define static data inside a class so you have to define it outside the class, after class definition either in header file

(Continued on next question...)

Other Interview Questions