struct student{
int id;
int score;
};
struct student* allocate(){
struct student* students = (struct student*)malloc(sizeof(struct student)*10);
return students;
}
void generate(struct student* students){
int i=0;
printf("%lu\n", sizeof(students));
printf("%lu\n", sizeof(struct student));
int length = sizeof(students)/sizeof(struct student);
printf("%d\n", length);
for(i=0;i<length;i++){
printf("hi\n");
}
}
I have this code which should create an array of 10 student structs. When I get to the generate function and try to see how much memory the students array had allocated it only says 8 bytes, the same as a single student struct itself and when I get to the for loop it is only printing "hi" once when it should be 8 times. What have I done wrong?
Output:
8
8
1
hi