Knowee
Questions
Features
Study Tools

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

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given C code will be 1.

Here's the step by step explanation:

  1. The #define directive in C is a pre-processor directive which is used to define symbolic names or macros. In the given code, #define int char is replacing all occurrences of int with char before the code is compiled.

  2. So, the line int i = 65; is actually interpreted as char i = 65; by the compiler.

  3. The sizeof operator in C is used to calculate the size of variables, constants, arrays, structures etc. The size of char is always 1 byte in C.

  4. Therefore, printf("%d", sizeof(i)); will print 1, because the size of i (which is a char due to the #define directive) is 1 byte.

This problem has been solved

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;}

1/4

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.