1. Home
  2. Computer Science MCQs
  3. C Programming
  4. What happens with sizeof(main) where main is a function…

Added 30 Nov -0001

What happens with sizeof(main) where main is a function returning int?

  1. It is a constraint violation, so a conforming compiler must diagnose it Correct answer
  2. It is the size of the code generated for the function, a few dozen bytes
  3. It is the size of a function pointer on that platform, typically 8 bytes
  4. It is 1, like sizeof(void), because functions are incomplete types in C

Correct answer

A. It is a constraint violation, so a conforming compiler must diagnose it

19 views

MCQSEXAM

Explanation

The operand of sizeof may not have function type: C11 6.5.3.4 makes sizeof applied to a function a constraint violation, so the compiler must issue a diagnostic. The usual decay of a function designator to a pointer does not happen for sizeof, & or the initialiser of a char array. sizeof of a function pointer, by contrast, is perfectly well defined.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? 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