Microsoft Interview Question


Country: United States
Interview Type: In-Person




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

Any c++ function which are using inline function will have more memory when they are being called in loops because it the code will expand at compile time and hence it will increase the memory size .instead of that if we have normal function only once the object code will be generated therefore it will take less memory .
Second - we can optimize c++ program by seeing when we are returning from function by value it created temporary variable for that they call constructor and destructor which also can be avoided ...

- sujeet kumar February 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

And also you can use reference returns on normal member functions with this pointer will avoid duplication of object, which means saving memory space, the inline functions are good only when they are smaller in size.

- Murali March 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In C++ the register keyword has no effect at all.

- Kili February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

one complement to comments above.
1. Cache
consider a big array long ar[100][100].
a) for (int i = 0; i < 100; ++i)
for (int j = 0; j < 100; ++j)
b) for (int j = 0; j < 100; ++j)
for (int i = 0; i < 100; ++i)
a) is better and faster, most-of-the-time, than b). Because a)'s traversal is smooth and using cache, while b) makes big jumps and cachemiss occurs. This also tells us to use vectors as a default container. As Stroustrup mentioned in GoNative2012, it has been tested that vectors run faster that lists even in heavy use of insertion and deletion.

- waiging.lau February 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

You'd want to mention that i is indexing into a row while j is indexing into a column. Without that, both a) and b) are identical. ;-)

- kaushcho March 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

we can create register variable instead of auto variable
like(register int i=0;i<128;i++)

it increase the performance
i m not sour but hopeful :)

- goelrinku90 February 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

class A { ... };
class B { ... };
class C {
A a;
B b;
C(A &a1, B &b1)
{
a = a1;
b = b1;
}
};

Good code:class A { ... };
class B { ... };
class C {
A a;
B b;
C(A &a1, B &b1): a(a1),b(b1)
{
}
};

- gendha fool February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

Huh? You seem to be missing the point of this site. OP is not asking for help (he has already given the interview). He is just posting the type of question that was asked, while being lazy. It is still helpful though.

- Anonymous February 05, 2013 | Flag


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