According to the C++23 standard, what is the output of this program?
#include <cstddef>
#include <iostream>
void f(void*) {
std::cout << 1;
}
void f(std::nullptr_t) {
std::cout << 2;
}
int main() {
int* a{};
f(a);
f(nullptr);
f(NULL);
}NULL is not necessarily an integer literal.
The program is unspecified / implementation defined
The macro
NULLis an implementation-defined null pointer constant.
A null pointer constant is an integer literal (§[lex.icon]) with value zero or a prvalue of type
std::nullptr_t.
In most implementations, NULL will be an integer literal and the program will not compile due to ambiguous call f(NULL). However, the C++ standard allows NULL to be a prvalue of std::nullptr_t in which case the program would output 122.
Here is an example where GCC and Clang use long for NULL, and MSVC uses int.