in Programming in C recategorized by
275 views
0 votes
0 votes
Explain the behaviour of following code:

int main()

{

int *j=0;

{

int i=10;

j=&i;

}

printf("%d",*j);

}

 

a. output is 10. j pointed to address of i, so it was not freed.

b. output may be 10 or garbage in given execution

c. output is 10. i becomes invisible outside of its block scope, but lives as long as function scope

d. output is 0.
in Programming in C recategorized by
275 views

1 Answer

2 votes
2 votes
When a variable goes out of scope, it's memory location is no longer valid. Accessing it causes undefined behaviour in C.
by

Related questions