What is typedef in C?

#include <stdio.h>

typedef struct {
    int roll;
    char name[20];
} Student;

int main(void) {
    Student s = {1, "Robin"};
    printf("%d %s\n", s.roll, s.name);
    return 0;
}

Output:

Output of the above program is

1 Robin

We wrote Student instead of struct Student. typedef does not create a new type, only a new name. See C typedef.


Learn more about the similar topics:
Tutorials
C Structures
C Nested Structure
C Array of Structures
C Pointer to Structure
C Union
C typedef
C enum
Exercises & Assignments
Write a C program to store and print student details using a structure
Interview Questions & Answers
What is the difference between structure and union in C?
What is typedef in C?
What is an enum in C?
What is structure padding in C?