search
Log In
0 votes
76 views
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 Algorithms 76 views

1 Answer

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

Related questions

2 votes
0 answers
1
148 views
Do any one know when the self administrator and other extra edge test can be seen in the login page.. after login I am only able to see section test, unit test and one extra edge test?
asked Jul 31, 2017 in GATE mystylecse 148 views
0 votes
2 answers
2
0 votes
1 answer
3
267 views asked Dec 14, 2017 in Programming VS 267 views
0 votes
1 answer
4
154 views
n=3 a[++n]=n++ Output : a[4]=4. How? Please explain it
asked Dec 4, 2017 in Programming Harikesh Kumar 154 views
...