Question 103Asked in BPSC TRE 2.0 (2023) Computer Science Class 11-12

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); } }
  1. A30,10
  2. B30,20
  3. C20,30
  4. DMore than one of the above
  5. ENone of the above
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.

From BPSC TRE 2.0 (2023) Computer Science Class 11-12 — Previous Year Paper

This is question 103 of BPSC TRE 2.0 (2023) Computer Science Class 11-12 — Previous Year Paper. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.