I have a hard time understanding what is the difference between
string name;
and
string name();
Could someone explain me the difference?
I have a hard time understanding what is the difference between
string name;
and
string name();
Could someone explain me the difference?
Assuming string
is a data type you have already declared, string name;
declares the variable name
of type string
.
The declaration string name();
declares the function name
that returns a value of type string
.
A variable is a place in memory where the program can store some data. A function is a piece of code that can be executed multiple times, when needed; it can receive (zero or more) arguments and it can optionally return one value.
string name; Declare the string data type variable 'name' in a memory where as string name(); shows the function prototype named as 'name' which returns the string value.