![]() |
default values for C struct fields
of course can't do this
typedef struct { char name[50] = "not_set_yet"; int ssn = 111223333; } employee; is: employee emp1 = {"not_set_yet", 111223333}; the only way? what is the most elegant way to have default values for all instances of that type of struct? |
Re: default values for C struct fields
You write it as C++, and supply a default constructor function.
Or if you're stuck with C, then your approach is one of several roughly equal approaches. None of which would be as elegant as using C++. |
Re: default values for C struct fields
if you want to initialize everything with a zero...
u can go for Code:
employee emp1 = {0}; |
Re: default values for C struct fields
Quote:
|
| All times are GMT +5.5. The time now is 16:51. |