R
Rishtaara
C Programming Fundamentals
Lesson 7 of 8Article16 min

Structures and Custom Types

Structures let you group related fields under one custom type. They are key for representing records like students, employees, and products.

Using struct for domain modeling

Structures let you group related fields under one custom type. They are key for representing records like students, employees, and products.

Struct declaration and usage
#include <stdio.h>

struct Student {
    char name[30];
    int grade;
    float marks;
};

int main(void) {
    struct Student s = {"Ishita", 12, 91.5f};
    printf("%s scored %.1f\n", s.name, s.marks);
    return 0;
}

typedef and nested structs

  • typedef improves readability for custom types.
  • Structs can contain other structs.
  • Combine structs with pointers for dynamic data models.