The above function has 2 default arguments. While calling this function if i want to use different value for only workex keeping default value of age as it is then how should i call this function?
printData("Tejas",,5);
I tried as above but it didn't work. Can someone please answer?
Sorry as I do not use default argument often but if I'm not wrong, the default arguments are usually referring to parameters to the right of the parameters you pass in.
In other programming languages, we can specify named parameter and their values.
E.g
//declare and define like below
void printData(char name[10],int age=24,int workex=3);
//use as below
void printData(name => "Tejas", workex=> 3);
Whether named parameters are useful is debatable. I believe it has a strong case when say your functions have >= 10 parameters. But then a function with >= 10 parameters mean your function is not designed to be "unit level of work" enough.
EDIT: Snipe'd by sohguanh. Unfortunately he did not understand what you requested, tshah.
Heh, it would be nice to do that. Unfortunately it doesn't work that way. If you want optional parameters, consider using pointers with NULL meaning Use Default.