Microsoft Interview Question for Software Engineer in Tests






Comment hidden because of low score. Click to expand.
1
of 1 vote

This is a linker error, because A::i was declared but not defined.

- Anonymous December 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Any static variable of a class is only declared in the class. It MUST be defined outside the class and within the same file as int A::i = 10;

- Tarun Tandon December 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

but all static variables will be initialized to zero right??

- Raju December 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what kind of question is this? do we have compilers and linkers?

- S December 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Tarun - I think tarun is right. Static variables are only glorified globals to which the access is protected by the compiler...

If you notice, static variables require no initialization to 0... meaning they don't contain garbage - they automatically are initialized to 0. This is a characteristic trait of globals in C/C++... Just a thought...

- Rohit January 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that the static variables can be accessed via static functions only.. so when you call the func using object A obviously you ll be getting the undefined reference. try it with static functions

- RashmiRamanathan January 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Only 1 bug:

1. 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 but more appropriately in corresponding .cpp

@Rashmi: According to above fact, you don't get compiler error since compiler's job is done by the declaration only, when linker tries to find i's definition it couldn't find because it is not defined outside and after the class A, so linker complained undefined reference just when linker was trying to resolve print() function's address. Also, static member data and static member functions are property of the class and bound to class only not to any object so you can call static member functions through objects also and static member data also can be accessed!

- rajendra February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Only 1 bug:

1. 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 but more appropriately in corresponding .cpp


@Rashmi: According to above fact, you don't get compiler error since compiler's job is done by the declaration only, when linker tries to find i's definition it couldn't find because it is not defined outside and after the class A, so linker complained undefined reference just when linker was trying to resolve print() function's address. Also, static member data and static member functions are property of the class and bound to class only not to any object so you can call static member functions through objects also and static member data also can be accessed!

- rajendra February 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

print here is not a static method. You can't call it without having an object for A.
A a = new A();

- WellSaid July 12, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More