Hello Everyone,
How to create default arguments in C? Is there any way to make default arguments ( i mean any alternative for them).
Hello Everyone,
How to create default arguments in C? Is there any way to make default arguments ( i mean any alternative for them).
The short answer is, you can't.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The standard library occasionally uses 0 or NULL as "don't care"-type arguments, but there's no way to leave them off entirely.
Standard approach will be having 2 functions
And call the first when you want to leave parameter d of InitializeEx with default valueCode:void Initialize(int a, int b, int c) { InitializeEx(a,b,c,103); } void InitializeEx(int a, int b, int c, int d) { //Do you work }
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
By the way, i have used this: » Preprocessor magic: Default Arguments in C - Intelligent rumblings
May be helpful for someone else.
Cheers