int x(int());
- this is the case of the most unpleasant parsing ; you consider this an int ( int x ) declaration, initialized to the default value for ints ( int() ); instead, the compiler interprets it as an declaration of a function returning an int , which takes as a parameter a function a (pointer), which takes no parameters and returns int (you can get hairy declarations explained by this site or get a better idea of type C declarations here )
Then when you do:
cout << x;
x splits into a pointer function here, but there is no operator<< overload that takes a pointer to a function; the simplest implicit conversion that gives some valid operator<< overload is bool , and since the function pointer cannot be 0 ( NULL ), it evaluates to true , which prints as 1.
Please note that I'm not quite sure that such code should be compiled without errors - you take the address of a function that is only declared and not defined; it is true that it cannot be evaluated by anything other than true , but in principle you should get a linker error (here it is masked by an optimizer that removes any link to x , since it is not actually used).
In fact, you wanted:
int x=int();
source share