This code doesn't work in C. Is there a way to have variable b take a default value of 2 in C?Code:#include <stdio.h> void func(int a, int b=2) { printf("%d",a+b); } int main() { func(1,1); func(1); return 0; }
Thanks!
This is a discussion on Default Arguments in C within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> void func(int a, int b=2) { printf("%d",a+b); } int main() { func(1,1); func(1); return 0; } This ...
This code doesn't work in C. Is there a way to have variable b take a default value of 2 in C?Code:#include <stdio.h> void func(int a, int b=2) { printf("%d",a+b); } int main() { func(1,1); func(1); return 0; }
Thanks!
No. Default arguments and function overloading are both specific to C++. There is no equivalent in C.
Right 98% of the time, and don't care about the other 3%.