is:
the same as:Code:struct student {
char id[10];
char name[26];
int gradePoints;
};
Code:struct {
char id[10];
char name[26];
int gradePoints;
} student;
Printable View
is:
the same as:Code:struct student {
char id[10];
char name[26];
int gradePoints;
};
Code:struct {
char id[10];
char name[26];
int gradePoints;
} student;
Nope.
The first declares a type named student, the second declares an object named student.
Interestingly, you could combine them like this:
Code:struct student {
char id[10];
char name[26];
int gradePoints;
} student;
There are conceivably [at least] four variants:
The above defines a type called "struct student". You need to use "struct student <name>" to create a variable <name>, which can then be used to store the id, name and gradepoints.Code:struct student {
char id[10];
char name[26];
int gradePoints;
};
Declares a variable called student, with an unnamed struct - this means that the struct can not be used to create any further variables than the statement it is in. This is very rarely useful, but there are situations where it can be useful.Code:struct {
char id[10];
char name[26];
int gradePoints;
} student;
Declares a struct student type, then a variable called student. You can create further instances just like in the first variant. [1]Code:struct student {
char id[10];
char name[26];
int gradePoints;
} student;
This declares a struct student, then declares a type of the name student as an "alias" name for that struct, so you can create a new variable struct student <name> by "student <name>".Code:typedef struct student {
char id[10];
char name[26];
int gradePoints;
} student;
[1] Note that in C++, an implicit typedef is made like the last example, and by using the same struct name and variable name, you are effectively hiding the implicit typedef. You can still use the C style "struct student <name>" to create further instances.
--
Mats