Goldman Sachs Interview Question
Software Engineer / DevelopersCould 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.
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
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!
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.
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