Knowee
Questions
Features
Study Tools

What is the correct way to initialize a 1D array named grades with values 850, 900, 780, 920, and 880 in C?

Question

What is the correct way to initialize a 1D array named grades with values 850, 900, 780, 920, and 880 in C?

🧐 Not the exact question you are looking for?Go ask a question

Solution

To initialize a 1D array named grades with values 850, 900, 780, 920, and 880 in C, you can follow these steps:

  1. Declare an integer array named grades with a size of 5. This can be done by writing:

    int grades[5];
    
  2. Assign the desired values to each element of the array. You can do this by using the assignment operator (=) and specifying the values in curly braces {}:

    grades[0] = 850;
    grades[1] = 900;
    grades[2] = 780;
    grades[3] = 920;
    grades[4] = 880;
    

Alternatively, you can initialize the array with the values directly in the declaration statement:

int grades[] = {850, 900, 780, 920, 880};

After following these steps, the array named grades will be initialized with the values 850, 900, 780, 920, and 880.

This problem has been solved

Similar Questions

What is the correct way to declare and initialize a one-dimensional array in C?

Which of the given options correctly initializes a 1D array with the first three natural numbers?

Which of the following is the correct way to initialize all the elements of array with 0?

Explain different ways in which you can declare and initialize a single dimensionalarray.

How do you initialize an array in C?a.int arr[3] = (1,2,3);b.int arr(3) = {1,2,3};c.int arr[3] = {1,2,3};d.int arr(3) = (1,2,3);

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.