How to Access Array of Structure in C? Last Updated : 19 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C, we can create an array whose elements are of struct type. In this article, we will learn how to access an array of structures in C. For Example, Input:myArrayOfStructs = {{'a', 10}, {'b', 20}, {'A', 9}}Output:Integer Member at index 1: 20Accessing Array of Structure Members in CWe can access the array of structures in a very similar to accessing array elements. To access members of an array of structures we can use the array indexing and access individual fields of a struct using the dot operator. Syntax to Access Array of Structure in CarrayName[index].member; Here, arrayName is the name of the array of struct.index is the position of the struct in the array that we want to access, starting from 0.member is the name of the member within the struct that we want to access.C Program to Access Array of Struct MembersThe below program demonstrates how we can access an array of structures in C. C // C Program to access the members of array of structure #include <stdio.h> // Defining the struct struct MyStruct { int id; char name[20]; }; int main() { // Declaring an array of structs struct MyStruct myArray[] = { { 1, "Person1" }, { 2, "Person2" }, }; // Accessing and printing data using array indexing printf("Struct at index 0: ID = %d, Name = %s\n", myArray[0].id, myArray[0].name); // Modifying the id of the second person myArray[1].id = 3; // Accessing and printing the updated information of the // second person printf("Struct at index 1 after modifying: ID = %d, " "Name = %s\n", myArray[1].id, myArray[1].name); return 0; } OutputStruct at index 0: ID = 1, Name = Person1 Struct at index 1 after modifying: ID = 3, Name = Person2 Time Complexity: O(1)Space Complexity: O(1) Comment More infoAdvertise with us Next Article How to Access Array of Structure in C? R rahul9yw89 Follow Improve Article Tags : C Programs C Language C-Arrays C-Structure & Union C Examples +1 More Similar Reads 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 Array of Structures in C An array of structures is simply an array where each element is a structure. It allows you to store several structures of the same type in a single array.Let's take a look at an example:C#include <stdio.h> #include <string.h> // Structure definition struct A { int var; }; int main() { // 5 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 How to Search in Array of Struct in C? In C, a struct (short for structure) is a user-defined data type that allows us to combine data items of different kinds. An array of structs is an array in which each element is of struct type. In this article, we will learn how to search for a specific element in an array of structs. Example: Inpu 2 min read How to Initialize Array of Structs in C? In C, arrays are data structures that store the data in contiguous memory locations. While structs are used to create user-defined data types. In this article, we will learn how to initialize an array of structs in C. Initializing Array of Structures in CWe can initialize the array of structures usi 2 min read How to Use bsearch with an Array of Struct in C? The bsearch function in C is a standard library function defined in the stdlib.h header file that is used to perform binary search on array-like structure. In this article, we will learn to use bsearch with an array of struct in C. Input: struct Person people[] = { { 1, "Ram" }, { 2, "Rohan" }, { 4, 3 min read How to Find the Size of an Array in C? The size of an array is generally considered to be the number of elements in the array (not the size of memory occupied in bytes). In this article, we will learn how to find the size of an array in C.The simplest method to find the size of an array in C is by using sizeof operator. First determine t 2 min read Array within Structure in C In C, a structure is a user-defined data type that allows us to combine data of different data types. While an array is a collection of elements of the same type. In this article, we will discuss the concept of an array that is declared as a member of the structure. Array within a Structure An array 3 min read How to Iterate Through Array of Structs in C? In C, while working with an array of structs we have to iterate through each struct in an array to perform certain operations or access its members. In this article, we will learn how to iterate through an array of the structs in C. Iterate Over of an Array of StructuresTo iterate through an array o 2 min read How to Create a Dynamic Array Inside a Structure? In C, the structure can store the array data types as one of its members. In this article, we will learn how to create a dynamic array inside a structure in C. Creating a Dynamic Array Inside a Structure in CTo create a dynamic array inside a structure in C, define a structure that contains a pointe 2 min read Like