Default parameters in C Default parameters in C c c

Default parameters in C


Default parameters is a C++ feature.

C has no default parameters.


It is not possible in standard C. One alternative is to encode the parameters into the function name, like e.g.

void display(int a){    display_with_b(a, 10);}void display_with_b(int a, int b){    //do something}


There are no default parameters in C.

One way you can get by this is to pass in NULL pointers and then set the values to the default if NULL is passed. This is dangerous though so I wouldn't recommend it unless you really need default parameters.

Example

function ( char *path){    FILE *outHandle;    if (path==NULL){        outHandle=fopen("DummyFile","w");    }else    {        outHandle=fopen(path,"w");    }}