What will be the output of the following C program?
#include <stdio.h>
int main()
{
char c = 'A';
printf("%d", sizeof(c));
return 0;
}
Options
-
A.
1
-
B.
2
-
C.
4
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
A.
1
Detailed Explanation
Correct Answer: 1
In C, the size of a char is defined to be exactly 1 byte.
Therefore, regardless of the character stored in the variable, sizeof(c) returns 1.
The important point is that sizeof measures the size of the data type, not the value stored in the variable.