Structs and Pointers
Use -> to reach fields through a struct pointer. Pass struct pointers to avoid copying and to allow changes. typedef gives structs short names.
Example
#include <stdio.h>
typedef struct { char name[16]; int score; } Student;
void bump(Student *s, int by) { s->score += by; }
int main(void) {
Student s = {"Ada", 70};
bump(&s, 5);
Student *p = &s;
printf("%s %d %d\n", p->name, p->score, (*p).score);
return 0;
}Result
Ada 75 75
Exercise
Access a field through a pointer.
pscore
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.