Monday 18 March 2013

variable's block


    main()
    {
        int *j;
        {
         int i=10;
         j=&i;
         }
         printf("%d",*j);
}
Answer:
10
Explanation:
The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space, *j prints the value stored in i since j points i.



Blog Author: Vijay Kumar

Go to: Java Aptitude

No comments:

Post a Comment