Interview Question

Staff Engineer Interview Matawan, NJ

Question on allocating memory pointers inside a function. A

  pointer variable is passed as a parameter to a function. Memory allocation is done inside the function for the pointer using malloc. After coming out of the function, will the pointer still retain this address in the main program?
Answer

Interview Answer

1 Answer

0

No. When pointer is passed as a function parameter, the address is copied like pass by value. Hence when it is out of the function, its address scope is last.

Interview Candidate on Jun 28, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up