Can I set a default argument from a previous argument?

The answer is no, you can’t. You could get the behaviour you want using overloads:

void f(int a, int b, int c);
inline void f(int a, int b) { f(a,b,b); }
inline void f(int a)        { f(a,a,a); }

As for the last question, C doesn’t allow default parameters at all.

Leave a Comment