PDA

View Full Version : C++ function arguments doubt?



rajeshs
24th September 2008, 09:58
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?

^NyAw^
25th September 2008, 18:39
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?

wysota
26th September 2008, 12:14
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:


void function(int, int);
The above statement is valid (you can skip variable names in function prototypes). Now what about this:

void function(int a, b);
is "b" a variable name or a data type?