codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C structures

C structures

Group different types.

A struct bundles related fields. Access with .; use -> through a pointer.

Example code

#include <stdio.h>
#include <string.h>
struct Student { char name[20]; int age; };
int main() {
  struct Student s = {"Ada", 21};
  printf("%s %d\n", s.name, s.age);
  return 0;
}

Run this code in the online editor

← C read filesNested structs and arrays of structs →