Answer to storing information in array

To store information in an array in the C programming language, you can follow these steps:

  1. Declare an array variable: Start by declaring an array variable with a specific data type and size. The data type determines the type of elements that can be stored in the array, such as integers, characters, or floats. The size specifies the number of elements the array can hold.

  2. Initialize the array: Optionally, you can initialize the array with initial values at the time of declaration. This step is not mandatory, and you can skip it if you want to assign values later.

  3. Assign values to array elements: Use assignment statements to assign values to individual elements of the array. You can access array elements using their index, which starts from 0 for the first element and increments by 1 for each subsequent element.

  4. Access array elements: You can access the values stored in the array by using the array variable name followed by the index of the element you want to access.

Here's an example that demonstrates these steps:

#include <stdio.h>

int main() {
    // Step 1: Declare an array variable
    int numbers[5];

    // Step 2: Initialize the array (optional)
    numbers[0] = 10;
    numbers[1] = 20;
    numbers[2] = 30;
    numbers[3] = 40;
    numbers[4] = 50;

    // Step 3: Assign values to array elements

    // Step 4: Access array elements
    printf("The value at index 2 is: %d\n", numbers[2]);  // Output: The value at index 2 is: 30

    return 0;
}

In this example, we declared an integer array numbers with a size of 5. We then initialized the array with values 10, 20, 30, 40, and 50. Finally, we accessed and printed the value at index 2, which is 30.

I hope this explanation helps! Let me know if you have any further questions.