0
0
Cprogramming~5 mins

Array initialization in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is array initialization in C?
Array initialization is the process of assigning values to an array at the time of its creation.
Click to reveal answer
beginner
How do you initialize an integer array of size 5 with values 1, 2, 3, 4, 5 in C?
int arr[5] = {1, 2, 3, 4, 5};
Click to reveal answer
intermediate
What happens if you initialize an array with fewer values than its size?
The remaining elements are automatically set to zero.
Click to reveal answer
intermediate
Can you initialize an array without specifying its size? How?
Yes, by letting the compiler count the values: int arr[] = {1, 2, 3}; The size is 3 automatically.
Click to reveal answer
intermediate
What is the difference between partial and full array initialization?
Full initialization assigns values to all elements. Partial initialization assigns values to some elements; the rest are zeroed.
Click to reveal answer
How do you initialize an array of 4 integers with all zeros in C?
Aint arr[4];
Bint arr[4] = {0};
Cint arr[4] = {};
Dint arr[4] = 0;
What is the size of the array in: int arr[] = {5, 10, 15}; ?
A0
B5
C3
DUndefined
If you write int arr[5] = {1, 2}; what are the values of arr[2], arr[3], and arr[4]?
A0, 0, 0
B1, 2, 0
CUndefined
D1, 2, 3
Which of these is NOT a valid way to initialize an array in C?
Aint arr[3] = {1, 2, 3};
Bint arr[3] = {0};
Cint arr[] = {4, 5, 6};
Dint arr[3] = {1, 2, 3, 4};
What is the value of arr[0] after this initialization? int arr[3] = {};
A0
BGarbage value
C1
DUndefined
Explain how to initialize an array in C and what happens if you provide fewer values than the array size.
Think about how you fill a row of boxes with some candies and leave the rest empty.
You got /3 concepts.
    Describe how the compiler determines the size of an array when you don't specify it explicitly during initialization.
    Imagine counting how many apples you put in a basket to know its size.
    You got /3 concepts.