Knowee
Questions
Features
Study Tools

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);

Question

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);

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

Solution

The correct way to initialize an array in C is option c. Here's how you do it:

  1. Declare the array with a specific size. In this case, the size is 3. So, you write int arr[3].

  2. Initialize the array with specific values. In this case, the values are 1, 2, and 3. So, you write = {1,2,3};.

  3. Put it all together. So, the final code is int arr[3] = {1,2,3};.

The other options are incorrect because they either use parentheses instead of square brackets, which is not the correct syntax for declaring an array in C, or they use parentheses instead of curly braces, which is not the correct syntax for initializing an array in C.

This problem has been solved

Similar Questions

Which of the following is the correct way to initialize an array in C++?int arr[3] = {1, 2, 3};int arr = {1, 2, 3};int arr[3] = 1, 2, 3;int arr[] = {1, 2, 3};

How is an array initialized in C language?int (a)=[1,2,3];int a[3]={1,2,3};int a[]=new int[3]int a={1,2,3};

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

How can you define an array in C/C++?*0/1A. array int[] B. int array{}C. int[] arrayD. int array[]

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

1/3

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.