How to Declare a Pointer to a Struct in C? Last Updated : 05 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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 CTo declare a pointer to a struct we can use the struct keyword. First, define a structure then declare a pointer to that structure using the below syntax and that pointer can be used to allocate and access memory for the structure. Syntax of Declaring Pointer to Structstruct StructName *ptr ;orstruct { // struct members} *ptr ;C Program to Declare Pointer to StructThe below example demonstrates declaration of pointer to a structure. C++ // C Program to show how to declare and use pointer to // structure #include <stdio.h> #include <stdlib.h> // Define a struct named Point with x and y coordinates struct Point { int x; int y; }; int main() { // Declare a pointer to a Point struct struct Point* ptr; // Allocate memory for a Point struct using malloc ptr = (struct Point*)malloc(sizeof(struct Point)); // Assign values to the x and y coordinates ptr->x = 10; ptr->y = 20; // Print the coordinates printf("Coordinates: (%d, %d)\n", ptr->x, ptr->y); // Free the allocated memory free(ptr); return 0; } OutputCoordinates: (10, 20) To know more, refer to the article - Structure Pointer in C Comment More infoAdvertise with us Next Article How to Declare a Pointer to a Struct in C? K kumardhanshiv Follow Improve Article Tags : C Programs C Language C-Struct-Union-Enum C-Pointers C Examples +1 More Similar Reads How to Declare a Pointer to a Union in C? Union is a user-defined data type in C language that can contain elements of the different data types and pointers are used to store memory addresses. In this article, we will learn how to declare a pointer to a union in C++. Pointer to Union in CTo declare a pointer to a union first, define a union 2 min read How to Declare a Struct Member Inside a Union in C? A union contains different types of variables as its members and all these members share a memory location. In this article, we will learn how to declare and access the struct member inside a union in C++. Structure Inside Union in CTo declare a structure inside a union we can use the below syntax: 2 min read How to Create an Array of Structs in C? In C, a structure is a user-defined data type that can be used to group items of different types into a single entity while an array is a collection of similar data elements. In this article, we will learn how to create an array of structs in C. Creating an Array of Structs in CTo create an array of 2 min read How to Initialize Char Array in Struct in C? In C++, we can also define a character array as a member of a structure for storing strings. In this article, we will discuss how to initialize a char array in a struct in C. Initialization of Char Array in Struct in CWhen we create a structure instance (variable) in C that includes a char array, we 2 min read How to Add an Element to an Array of Structs in C? In C, a struct is a user-defined data type that allows the users to group related data in a single object. An array of structs allows to store multiple structs in contiguous memory locations. In this article, we will learn how to add an element to an array of structs in C. Example: Input: structArra 3 min read Like