I can access the char value of the nested struct, but the int one it shows memory address only, how I can dereference the pointer value of an int one ? here is a sample code:
#include <stdio.h>
struct Class {
char name[10];
int cap;
};
struct Student {
char firstname[10];
char lastname[10];
struct Class *class[5];
};
void printStudents(struct Student *student) {
struct Class *class;
class = student->class[2];
printf("Capacity => %d\n", &class->cap);
printf("Class => %s\n", &class->name);
}
int main(void) {
struct Class class[] = {
{"rust", 8},
{"python", 22},
{"java", 33}
};
struct Student student = {"Ian", "saeidi", (struct Class *) &class};
struct Class class[] = {
{"rust", 8},
{"python", 22},
{"java", 33}
};
struct Student student = {"Ian", "saeidi", &class};
printStudents(&student);
return 0;
}
Output:
Expected Output:
Capacity => 33
Class => java
I have tried the below initialization still does not worked, and the editor says that it is element 0, while I have added the entire struct array:
struct Class class[] = {
{"rust", 8},
{"python", 22},
{"java", 33}
};
struct Student student = {"Ian", "saeidi", (struct Class *) &class};
struct Class class[] = {
{"rust", 8},
{"python", 22},
{"java", 33}
};
struct Student student = {"Ian", "saeidi", &class};