1. Home
  2. Computer Science MCQs
  3. C Programming
  4. A goto statement jumps forward over the declaration int…

Added 30 Nov -0001

A goto statement jumps forward over the declaration int a[n]; inside the same block. Why does a conforming C compiler reject this?

  1. Because goto may not cross any declaration that has an initialiser
  2. It is rejected only when n is a compile-time constant expression
  3. Jumping into the scope of a variably modified object is not permitted Correct answer
  4. The jump is legal, but the array a stays uninitialised until it is used

Correct answer

C. Jumping into the scope of a variably modified object is not permitted

16 views

MCQSEXAM

Explanation

A variably modified type such as int a[n] needs storage whose size is known only at run time, so entering its scope by a jump would skip that allocation. C11 6.8.6.1 therefore makes it a constraint violation to goto into the scope of such an identifier, while jumping out of the block is fine. Ordinary fixed-size declarations may be skipped, which is why int a[10] raises no diagnostic.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs