0
0
Cprogramming~10 mins

Array initialization in C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an integer array named numbers with 5 elements.

C
int numbers[[1]];
Drag options to blanks, or click blank then click option'
A1
B10
C0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the brackets empty, which is not allowed in C for array declaration.
Using zero or negative numbers as array size.
2fill in blank
medium

Complete the code to initialize the array with values 1, 2, 3, 4, 5.

C
int numbers[5] = [1];
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4, 5]
B{1, 2, 3, 4, 5}
C(1, 2, 3, 4, 5)
D<1, 2, 3, 4, 5>
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of curly braces.
Missing commas between values.
3fill in blank
hard

Fix the error in the array initialization to correctly initialize an array of 3 floats.

C
float values[3] = [1];
Drag options to blanks, or click blank then click option'
A{1.0, 2.0, 3.0}
B(1.0, 2.0, 3.0)
C[1.0, 2.0, 3.0]
D1.0, 2.0, 3.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Not enclosing the values in any brackets.
4fill in blank
hard

Fill both blanks to declare and initialize an array of characters with the letters 'a', 'b', 'c'.

C
char letters[[1]] = [2];
Drag options to blanks, or click blank then click option'
A3
B{'a', 'b', 'c'}
C{"a", "b", "c"}
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes for characters instead of single quotes.
Mismatch between array size and number of elements.
5fill in blank
hard

Fill all three blanks to declare and initialize an integer array with values 10, 20, 30, and access the second element.

C
int arr[[1]] = [2];
int second = arr[[3]];
Drag options to blanks, or click blank then click option'
A3
B{10, 20, 30}
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 2 to access the second element instead of 1.
Mismatch between array size and number of elements.