ProgrammingHardWipro · Accenture · Capgemini pattern
What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { char grade = 'B'; switch (grade) { case 'A': case 'B': printf("Good"); break; case 'C': printf("Average"); break; default: printf("Unknown"); } return 0; }
- A. Good
- B. GoodAverage
- C. Unknown
- D. Average
Correct answer: A. Good
Case 'A' has no break, so it falls through to share case 'B'\'s body; since grade is 'B', "Good" is printed either way.
More C Programming questions
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs…
- In C, sizeof(char) is:
- Which storage class makes a local variable keep its value between calls to the function?
- The end of a C string is marked by:
- Which declaration makes p a pointer to an int?
- A line such as #include <stdio.h> is processed by: