C++ function arguments doubt?
I have one doubt with C++ function arguments declaration;
Normally if want to declare more than one variables with same type,C++ have option to declare with in same declaration ; ( int a,b ; this will declare a and b same int type);
Why this option is disabled when come to function arguments ? (We can't specify function arguments as void display(int a,b) ; we should specify type for both argumrnts seperatly)
Is there any reason to do this?
Why language designers disabled this option in function argunments?
Re: C++ function arguments doubt?
Hi,
Maybe then the compiler needs to know if "b" is a defined type.
When defining variables the compiler reads the first word and know wich type are the varaibles that will follow separated by ",".
Then, in a function you can do this: "foo(int a,b,double c)", and then the compiler will search for type "b" that don't exists.
A coder writes a lot of code lines, so, are you complaining to write some words?
Re: C++ function arguments doubt?
In regular code semicolon is used as statement separator. Inside function declaration the comma character is used as a separator. Thus you can associate variable names with the type in regular code but not in function arguments. Consider this example:
Code:
void function(int, int);
The above statement is valid (you can skip variable names in function prototypes). Now what about this:
Code:
void function(int a, b);
is "b" a variable name or a data type?