#include <iostream>
int main(){
std::cout << main << std::endl;
return 0;
}
Why it prints 1 in command line ?
#include <iostream>
int main(){
std::cout << main << std::endl;
return 0;
}
Why it prints 1 in command line ?
Your program is ill-formed. N4140:
§3.6.1/3 The function
main
shall not be used within a program. [...]
If we pretend that the program wasn't ill-formed, the most likely explanation is the standard conversions:
§4.3/1 An lvalue of function type
T
can be converted to a prvalue of type "pointer toT
." The result is a pointer to the function.§4.12/1 A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type
bool
. A zero value, null pointer value, or null member pointer value is converted tofalse
; any other value is converted totrue
. For direct-initialization (8.5), a prvalue of typestd::nullptr_t
can be converted to a prvalue of typebool
; the resulting value isfalse
.
If you insist on doing this, try:
std::cout << (void*)main << std::endl;