Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
int main() {
char code[4] = "PUNE1";
std::cout << code << '\n';
return 0;
}
- A char arrays cannot hold letters
- B "PUNE1" needs 6 chars including the terminating '\0', but the array has only 4 Correct
- C cout cannot print char arrays
- D Strings need single quotes
Correct Answer: Option B
A string literal includes its null terminator. Write char code[] = "PUNE1"; (size 6) or use std::string.
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!