After learning from this question that in C++ It is okay to put the name of the variable in parenthesis
I tried this program:
#include <iostream>
int main()
{
int (a)();
std::cout << "if this works then deafult value of int should be " << a << std::endl;
return 0;
}
And got output of ‘if this works then deafult value of int should be 1’
So, is this true?
EDIT::
After reading @james-mcnellis answer when i tried to assign a value to a, it gives an error as assignment of function ‘int a()’.
so now it is clear that here a is a function not the variable.
ais not anint: it is a function that has no parameters and returns anint. Because it is a function declaration,ais also not a local variable and it does not have a “default value.”The program is ill-formed because you never define the function
abut you attempt to use it (by taking its address in the insertion expression). It therefore violates the one definition rule.If you define
ain the program,1will be printed because the address of the functionawill be converted tobool: theoperator<<overload that has aboolparameter is the best match for the function pointer argument type.[Note: if you define
aand compile with Visual C++, it will print the address of the function, not1. This is (I think) because Visual C++ allows a function pointer to be implicitly converted tovoid*, and then theoperator<<overload that has avoid const*parameter is the best match for the function pointer argument type. If you compile with language extensions disabled (/Za), the overload with aboolparameter will be selected as expected.]