C - Data Types - Discussion

You Are Here :: Home > C > Data Types - Discussion

 



Q.

What will be output of following c program?

#include
int *call();
void main(){
int *ptr;
ptr=call();
fflush(stdin);/div>
printf("%d",*ptr);
}
int * call(){
int x=25;
++x;
return &x;
}

A. 25 B. 35
C. Compile time error D. Garbage value

Answer: Option D
Explaination:

variable x is local variable. Its scope and lifetime is within the function call hence after returning address of x variable x became dead and pointer is still pointing ptr is still pointing to that location.



Discussion

Your Comments Goes here...
NameDiscussion