A goto statement jumps forward over the declaration int a[n]; inside the same block. Why does a conforming C compiler reject this?
Correct answer
C. Jumping into the scope of a variably modified object is not permitted
16 views
C. Jumping into the scope of a variably modified object is not permitted
16 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.