ProgrammingHard
printf("%s", (char[]){'h', 'i', '\0'}); What is printed?
- A. h
- B. hi
- C. hi\0
- D. ih
Correct answer: B. hi
The compound literal is a char array with a terminator, so printing it gives hi.
More C Programming questions
- char a = "ab", b = "ab"; printf("%d", strcmp(a, b) == 0); What is printed?
- char buf[8] = "12345"; buf[strlen(buf) - 1] = '0'; printf("%s", buf); What is printed?
- char s[] = "abc"; printf("%c", s[sizeof s - 1]); What is printed?
- printf("%d", (int)sizeof(char)); What is printed in C?
- char w[] = "one two"; char p = w; while (p && p != ' ') p++; printf("%d", (int)(p - w)); What is printed?
- char s[] = "aXbXc"; int x = 0; for (int i = 0; s[i]; i++) x += s[i] == 'X'; printf("%d", x); What is printed?