1. You can, but if x == -1, and you return -1, and in other cases you return x, that reduces to return x;
To be less of a donkey about it, yes, something like this works.
Code:
return x == something ? -1 : x;
2. What you wrote there is a structure declaration. When you define a variable to be your structure type, then you will get the opportunity to make the flag be some value. As far as I'm aware, there is no notion of default values like in C++.
If you need to be certain that the struct is given certain values, you can use the
opaque pointer idiom, and force the programmer to write something like:
Code:
struct student *classmate = student_init("John Doe", 123456, 0, 0, 0);
Then inside the function you can ensure the initial flag value, 't'. You have to design a suite of functions around the structure to use it, but it's worth it in the end in most real-world situations.