ProgrammingModerateTCS NQT · Infosys

What is printed? Assume int is 4 bytes.

What is printed? Assume int is 4 bytes.
#include <stdio.h>
int main(void) {
    printf("%zu", sizeof('a'));
}
  1. A. 1
  2. B. 8
  3. C. 2
  4. D. 4

Correct answer: D. 4

Character constants in C have type int, so sizeof 'a' is the size of int, which is 4 here. In C++ the same expression gives 1.

More C Programming questions

Exams that ask this topic