ProgrammingVery hard
char s[] = "ab"; char *q = s + 2; printf("%d", *q); What is printed?
- A. 98
- B. 97
- C. undefined behaviour
- D. 0
Correct answer: D. 0
s + 2 points at the terminator of the three-byte array, which holds 0. Dereferencing it is defined.
More C Programming questions
- char c = 'A'; printf("%d %c", c + 1, c + 1); What is printed?
- printf("%s", "abc" + 1); What is printed?
- char name[] = "Bob"; char p = name; printf("%c%c", p[0], (p + 2)); What is printed?
- char buf[] = "ab"; buf[2] = 'c'; printf("%zu", sizeof buf); What is printed?
- char s[3] = "ab"; printf("%zu", sizeof s); What is printed?
- char a = "xy"; char b = a; b[0] = 'z'; printf("%s", a); What is printed?