Broadcom interview question

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?

Interview Answers

Anonymous

Jun 28, 2012

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.

Anonymous

Jan 18, 2021

In these sorts of interviews you really need to drill down and understand what the interviewer is looking for. A good way to simulate a real interview experience is to do a mock with one of the Broadcom Staff Engineer experts on Prepfully, rated super strongly on TrustPilot... prepfully.com/practice-interviews