Question discussion

What is the output of the following C program?#include int main() { printf("%d %d %d", (int)sizeof('a'), (int)sizeof("ab"), (int)sizeof(1.5…

980Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    printf("%d %d %d", (int)sizeof('a'),
           (int)sizeof("ab"), (int)sizeof(1.5f));
    return 0;
}
  • A4 3 4
  • B1 2 4
  • C1 3 8
  • D4 2 8
Correct answer: A

Explanation

In C a character constant has type int (4 bytes), "ab" is a char array of 3 bytes including '\0', and 1.5f is a 4-byte float.

Discussion 0

Nobody has replied yet. Start the discussion!