Multiple choice

What will be the output of the following program fragment? #include<iostream.h> int i=10; int main() { int i=20; { int i=30; cout<<i<<::i; } return 0; }

  1. Prints 3020

  2. Prints 3010

  3. Will result in run time error

  4. Prints 3030

  5. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

First 'i' will be printed as 30, as preference is given to local variable. In front of second 'i', ::(scope resolution) operator is given. :: means to manipulate a global variable, in case a local variable also has the same name.