Question 15
Back to Exercise
What is the output of the following C++ program?
#include <iostream>
void f(int) { std::cout << "int "; }
void f(const char*) { std::cout << "pointer "; }
int main() {
f(0);
f(nullptr);
f("0");
f('0');
std::cout << '\n';
return 0;
}
- A int pointer pointer int Correct
- B pointer pointer pointer int
- C int int pointer int
- D int pointer pointer pointer
Correct Answer: Option A
0 is an int; nullptr converts only to pointers; "0" is a string literal (const char*); '0' is a char, promoted to int.
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!