Default parameters in C

user1128265 picture user1128265 · Feb 8, 2012 · Viewed 50.9k times · Source

Is it possible to set values for default parameters in C? For example:

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

main(){
  display(1);
  display(1,2); // override default value
}

Visual Studio 2008, complaints that there is a syntax error in -void display(int a, int b=10). If this is not legal in C, whats the alternative? Please let me know. Thanks.

Answer

ouah picture ouah · Feb 8, 2012

Default parameters is a C++ feature.

C has no default parameters.