Question 5
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
const char *p = NULL;
const char *q = "";
printf("%d %d %d\n", p ? 1 : 0, q ? 1 : 0, q && *q);
return 0;
}
- A 0 1 0 Correct
- B 0 0 0
- C 0 1 1
- D 1 1 0
Correct Answer: Option A
p is a null pointer (false). q is a valid pointer (true) to an empty string, whose first character is '\0' (false). "Not NULL" and "not empty" are two different checks.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!