PreprocessorWhat will be the output of the following C code?#include <stdio.h>#define int charvoid main() { int i = 65; printf("%d", sizeof(i));}Options42Compilation Error1
Question
PreprocessorWhat will be the output of the following C code?#include <stdio.h>#define int charvoid main() { int i = 65; printf("%d", sizeof(i));}Options42Compilation Error1
Solution
The output of the given C code will be 1.
Here's the step by step explanation:
-
The
#definedirective in C is a pre-processor directive which is used to define symbolic names or macros. In the given code,#define int charis replacing all occurrences ofintwithcharbefore the code is compiled. -
So, the line
int i = 65;is actually interpreted aschar i = 65;by the compiler. -
The
sizeofoperator in C is used to calculate the size of variables, constants, arrays, structures etc. The size ofcharis always 1 byte in C. -
Therefore,
printf("%d", sizeof(i));will print 1, because the size ofi(which is achardue to the#definedirective) is 1 byte.
Similar Questions
What will be the output of the following C code?
what will be the output of the c program?
PreprocessorWhat will be the output of the following C code?#include <stdio.h>#define int charvoid main() { int i = 65; printf("%d", sizeof(i));}Options42Compilation Error1
What will be the output for the following code?12345678910111213#include <stdio.h>void setZero(int *num) { *num = 0;}int main() { int i = 10; int *ptr = &i; setZero(&(*ptr)); printf("%d", *ptr); return 0;}
What will be the output of the following C code?#include <stdio.h>int main() { int i; for (i = 0; i < 5; i++); printf("%d\n", i); return 0;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.