What's the effect of int a();
in C++?
Is it equivalent to int a
or int a(0)
?
And how about char c()
and double d()
?
What's the effect of int a();
in C++?
Is it equivalent to int a
or int a(0)
?
And how about char c()
and double d()
?
What's the effect of
int a();
in C++?
That declares a function, with no parameters, that returns an integer.
Is it equivalent to
int a
orint a(0)
?
No. Each of these declares a variable of integer type; the second also initialises it with the value zero.
And how about
char c()
anddouble d()
? Thanks.
These also declare functions, with different return types.
int a();
is a function declaration.
int a
is declaring a
to be of type int
.
int a(0)
is declaring a to be of type int
and initialising it to 0
.
char c()
and double d()
are function declarations also returning char
and double
respectively.
All the function declarations should be terminated by a ;
.
Neither, it declares a function.