Interview Question for Software Engineer / Developers






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

when i ran the above code with initial value 10, upper gets initialised but not lower.

- kim January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I tried running the same .the lower doesn't get initialised. can somebody explain why?

- mike January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess the names of the member variables appearing on the Initialization list should be in the same order as they appear in the class (declaration).

- Aditya January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There initialization take place in order of there declaration,,,
so by that I mean first upper get initialized and after that lower,,
So in the previous questions assuming i to be 10
upper = unknow lower value + 1 //
lower = 10

- Anonymous January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

on my pc, lower is initialized (equals i)
but not upper

But I have no idea about why

- Anonymous February 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

from c++ primer: the initializer only shows which value to set which member, but the order of initializers has no meaning

compiler will set upper first, then lower

therfore
A1( int i ) : upper( lower+1 ) , lower( i ){ };
// lower = 10; upper = 11

- Anonymous February 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey Anonymous, there is a small correction. upper will get initialized first. But at that time the value of lower is unknown. So upper value will be = unknown + 1.So we cant predict that it will be 11.
Next lower get initialized with i . so its value will be 10

- prep4Inter February 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Always remember the initialization order is
1) Super Class (Based on the inheritance order, not mem init list)
2) Memeber (Based on the order they declared in class, not mem init list)
3) Computation inside the constructor

- Mimi March 02, 2010 | 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