What will be the output of the program?
Correct Answer : E
The scope of a variable is the part of program in which it is alive / visible.
In the above program, variable
i is declared in
for loop. So its scope is only the
for block. It can not be used outside its scope. But display statement tries to print value of
i, after the
for loop, where it is not in scope. This leads to compilation error.
So, the answer is E.