What will be the output of the following program?
int *call();
void main() {
int *ptr = call();
printf("%d : %u",*ptr,ptr);
clrscr();
printf("%d",*ptr);
}
int *call() {
int x = 25;
++x;
//printf("%d : %u",x,&x);
return &x;
}
Expected Output: Garbage value
Actual Output: 26 #someaddr
Since x is a local variable it's scope ends within the function call. I found this code as an example for dangling pointer.