# C++ Arrays and Structures

Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. Arrays are a fundamental data structure and are often used to store and manipulate a fixed number of elements.

### Declaring and Initializing Arrays:

You can declare and initialize an array in C++ using the following syntax

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695905304116/3371bbe5-a597-402d-b357-3cc2d44f636b.png align="center")

Example:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695905466210/d91475ea-e754-4b8b-969b-76f1ae4d970e.png align="center")

Now declaration of values:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695905537665/1163b502-4813-4a6c-977e-e1e8e28d5dec.png align="center")

To access the Elements of the array:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695905610987/8c9bbeff-d3fa-46aa-bd87-bfcef3a70ed9.png align="center")

Now, you can change the value of a specific element we can do it by the index of a number:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695905698987/76e43aac-4441-4bce-a910-d30cc6815b9a.png align="center")

Storing Multiple Arrays:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695906019133/0422bd0f-1293-486e-afc8-39e8e465fe9c.png align="center")

**Structures:**

Structures are also called as the struct is a way to group several related variables into one place. Each variable in the structure is known as the member of the structure.

### Steps for Creating a Structure Variable:

1. **Create a structure variable that is myStructure**
    
    struct {  
      int myNum;  
      string myString;  
    } myStructure;
    
2. **Assign values to members of myStructure**
    
    myStructure.myNum = 1;  
    myStructure.myString = "Hello World!";
    
3. **print members of myStructure**
    
    cout &lt;&lt; myStructure.myNum;  
    cout &lt;&lt; myStructure.myString;
    

One more example of the structure is:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1695907969817/45015d14-a2d8-42d5-8088-b315f59cb2d8.png align="center")

Thanks for reading,

Mohammed Muqafamuddin.
