![]() |
Interview question.
A good question usually asked at interviews,-
/**************************/ int * func(int, int); void main() { int *ptr = func(2,3); printf("\nHello World!\n"); printf("\n%d\n",*ptr); } int * func(int i, int j) { int k = i + j; return &k; } /**************************/ What will be the output of the above program? Scroll down for answer. Here is the output,- Hello World! Garbage Value Note that Garbage Value will be printed here instead of 5. This is because once the control returns from func() to the main(), the address of local variable 'k' is free. So the contents of this address can be modified by anybody else. |
Re: Interview question.
Quote:
Code:
void AllocateMem(int *p)Scroll down for an answer Code:
void AllocateMemory(int **p) |
Re: Interview question.
I will add one
Code:
class AScroll down for an answer 2 4 because there is a Pointer to the virtual table to resolve the dynamic binding of the virtual function. |
Re: Interview question.
Some multiple choice questions in C/C++ thread will add to the current questions.
|
| All times are GMT +5.5. The time now is 06:19. |