ProgrammingHardProduct-company MCQ pattern

Compiled as C with 4-byte int, what is printed?

Compiled as C with 4-byte int, what is printed?
printf("%zu %zu", sizeof('A'), sizeof(char));
  1. A. 4 4
  2. B. 1 1
  3. C. 2 1
  4. D. 4 1

Correct answer: D. 4 1

In C a character constant such as 'A' has type int, so sizeof('A') = sizeof(int) = 4. sizeof(char) is always 1. In C++ 'A' has type char and the output would be 1 1.

More C Programming questions

Exams that ask this topic