What happens if you try to compile and run this program?

What happens if you try to compile and run this program?

#include <stdio.h>

int main (int argc, char *argv[]) {

char *p = "John" " " "Bean";

printf("[%s]", p) ;

return 0;

}

Choose the right answer:
A . The program outputs "[]"
B . The program outputs nothing
C . The program outputs [John Bean]
D . The program outputs three lines of text
E . The program outputs two lines of text

Answer: C

Explanation:

The string literal "John" " " "Bean" is effectively concatenated into a single string by the compiler during compilation. Therefore, the value of p becomes a pointer to the string "John Bean". The printf statement then prints the string enclosed within square brackets, resulting in the output [John Bean].

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments