Goldman Sachs Interview Question for Software Engineer / Developers






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

No compilation error will be given. Pointer variable p contains garbage value. If we try to dereference p inside main function, we'll get run time error (if the garbage value inside p is some restricted memory location).

- Abhishek Soni April 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Could you please explain why it will give compiler error??
I think it should work fine. you are passing an uninitialized pointer to a void function. and it will update the local value of that pointer. So i don't see any thing wrong in it.

- Anon April 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there will be no error in the given program, it ill be compiled and executed without any error.

- nivedita March 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

you would get a compiler error saying: The varaible p is being used without getting initialized. It doesn't matter if you send p to a function that returns void.

it is like accessing the value at p without actually initializing it.

-veeru

- Anonymous April 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't think we are accessing the value of p anywhere. program assigns a value to p which shouldn't be problem.

- Anon April 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

no error.. no output...

- Sarath April 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No error

- Anonymous April 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Depends on the compiler warning options. -Wall will give you an uninitialized variable error, otherwise no error. In a large project you might be checking in code that will be compiled with different options depending on the target environment. -Wall and debugging symbols for testing, or stripped for production. But what a poorly designed question, esp in a multiple choice test format!

- Anonymous April 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A warning is expected but not a compiler error.

- Vijay Rajanna May 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i got variable p used without being initialized error

- zeeshan May 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No compile error

- Vipul May 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

no error

- eurekha85 July 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

NO TERI BHEN DI

- DADDY August 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No error...........no output...
I compiled this program on gcc, Please correct me if i am wrong.

- balakrishna September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pointer p points to the address of the local object... So basically the object gets destructed before returning to main() and will be left out with garbage, junk...

- kalee November 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There will be no compiler and no run time error. But there are two things to notice first, 'v' in called function will be destroyed after becoming out of scope and we are passing raw pointer (which is not pointing to any memory) to function, in that case, called function will it self create a pointer of int and any change on this pointer will not be reflected on main 'p' pointer.

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

To me the answer is 0 the compiler gave result

- Anonymous August 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

abe sale hemant
kis compiler pe run kia tha

- mayank November 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its depend on the compiler. Pointer p holds the address of actual v and after the section of fun() function. veriable V's scope get closed. mean time that momey is push to stack. so you can't use it. in main function. it display the garbage value.
But not a compiler error.

am i right ?

- Shrikant Badiger September 19, 2013 | 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