C structures and records

A struct combines fields under a named type. It can represent one student with a name and a score while keeping their association explicit.

C
#include <stdio.h>
#include <assert.h>
struct Student { char name[20]; int score; };
int main(void) {
    struct Student first = {"Ada", 82};
    struct Student second = first;
    second.score = 95;
    printf("%s %d\n", first.name, first.score);
    printf("%s %d\n", second.name, second.score);
    assert(first.score == 82);
    return 0;
}
Read the full lesson