why is declaring or defining a function without the parameters names acceptable?

declaring or defining a function without parameter name is acceptable

When we declare a function mentioning only the parameter type without it’s name the compiler will accept it.For instance look at the code below.


void func(float , float , float ) ;   ///Works fine

And also when a function is defined mentioning only the parameter type without the identifier(name) is also accepted by the compiler.Consider the function definition given below.

#include <iostream>

using namespace std ;

void func( float , float , float);   //work fine


int main( )
func(1.77 , 0.69 , 7.367 ) ;

cin.get( ) ;
return 0 ;

When a function call is made the Compiler scans only the type of the arguments passed to the function and accordingly figures out which function to call;if the function have same name the compiler will differentiate them base on their parameters type.So the above function declaration or definition is valid.However,defining a function without it’s parameters name holds a disadvantage for us.In the above function we could not make any use of the values passed to the function since we cannot access the values without it’s parameters names.So,it is always better to give an argument name while defining a function.


Related Link

->C++ Function:Declaration and definition.
->C++ function parameters and arguments.