#include <stdio.h>
#include <string.h>
const int NAMELEN=30;
const int MAXCLASSSIZE=10;
typedef struct StudentRec {
char lastname[NAMELEN];
char firstname[NAMELEN];
long int ID;
int finalmark;
}Student;
I'm new to coding..and I have a question about why there is Student; after the bracket.. is it a format that we have to follow.
you are confusing two things. In C you can define a struct like this:
struct foo {
int a, b;
};
Then to use one you have to do this:
struct foo myFoo;
This is really wordy, so they had this brilliant idea of using typedef to make a new type. I can do something like this:
typedef int myInt;
and then use it:
myInt x;
So what you're doing is declaring that there is a new type, Student, which is equivalent to a struct StudentRec. By convention, many people use the same name for the typedef as for the struct - it is legal:
typedef struct foo { int a, b; } foo;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With