What will be the output of the following program fragment? int i = 10;
What will be the output of the following program fragment?
int i = 10;
void main( )
{ int i = 20;
{
int i = 30;
printf("%d, %d", i, ::i);
}
}
Show answerHide answer
Correct answer: (A) 30,10
Explanation
The innermost i is 30. ::i is the scope resolution operator and refers to the global i, which is 10, so the output is 30,10. Note that :: is valid in C++, not C.