Program for further scope of variables with Explanation
Program
#include <stdio.h>
main()
{
int k = 10;
}
for(int i=0;i<2;i++)\\ A
{ \\ B
printf("value of i is %d\n",i); \\ C
} \\ D
{
printf("the value of i is %d\n",i); \\ E
}
Explanation
The counter variable i is defined at statement A.
The scope of the for loop is up to statement D, which is the end of the for loop for statement B.
If you do not comment out statement E, you will get an error, because you cannot refer i in the outside block.
No comments:
Post a Comment