How to use typedef for a Struct in C? Last Updated : 19 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C, we use typedef to create aliases for already existing types. For structure, we can define a new name that can be used in place of the original struct name. In this article, we will learn how to create a typedef for a structure in C++. Use the typedef struct in CTo create an alias for a structure in C, we can use the typedef keyword typedef for a structure that provides the existing datatype with a new name. SyntaxFor defining the structure and creating a typedef simultaneously use: typedef struct StructName { // Member definitions} TypedefName;For defining the Structure first, then creating a typedef use: struct StructName { // Member definitions};typedef struct StructName TypedefName;C Program to Create an Alias Using typedef for a structThe below program demonstrates the use typedef keyword to create a typedef for a structure in C. C // C program to create a typedef for a structure #include <stdio.h> // Defining the structure struct Student { char name[50]; int age; float gpa; }; // Creating a typedef for the struct typedef struct Student St; int main() { // Declaring a variable using the typedef St student1; // Assigning values to the struct members snprintf(student1.name, sizeof(student1.name), "Ram"); student1.age = 20; student1.gpa = 9.5; // Displaying the information of a student printf("Student Information:\n"); printf("Name: %s\n", student1.name); printf("Age: %d\n", student1.age); printf("GPA: %.2f\n", student1.gpa); return 0; } OutputStudent Information: Name: Ram Age: 20 GPA: 9.50 Comment More infoAdvertise with us Next Article How to Use typedef for a Union in C? 21211a4uyj Follow Improve Article Tags : C Programs C Language C-Structure & Union C-Data Types C Examples +1 More Similar Reads How to Use typedef for a Union in C? In C, typedef is used to give an existing type an alias or a new name. In this article, we will learn how to create a typedef for a union in C. Use the typedef union in CWe can define a union and create an alias for it using the typedef keyword which we will be able to use in place of that union nam 2 min read How to Write a Struct to a Binary File in C? C file handling allows users to store the data from a C program to a file in either the text or the binary format. In this article, we will learn how to write a struct to a binary file in C. Writing Structure into a Binary File in CTo write a struct to a binary file, we can use the fwrite() function 2 min read How to Pack a Struct in C? In C, when you declare a structure, the compiler allocates memory for its members, and the way it does this can involve adding padding between members for alignment purposes. struct packing refers to the arrangement of the members of a structure in memory so that there is no extra space left. In thi 1 min read How to Create a Typedef for a Function Pointer in C? In C, a function pointer is a variable that stores the address of a function that can later be called through that function pointer. The typedef is a keyword used to create an alias or alternative name for the existing data types. In this article, we will learn how to create a typedef for a function 2 min read How to Declare a Pointer to a Struct in C? Structure (or structs) in the C programming language provides a way to combine variables of several data types under one name and pointers provide a means of storing memory addresses. In this article, we will learn how to declare such a pointer to a struct in C. Declaration of Pointer to Struct in C 2 min read How to Pass Array of Structure to a Function in C? An array of structures in C is a data structure that allows us to store multiple records of different data types in a contiguous memory location where each element of the array is a structure. In this article, we will learn how to pass an array of structures from one function to another in C. Passin 2 min read Like