0
0
Cprogramming~5 mins

One-dimensional arrays in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a one-dimensional array in C?
A one-dimensional array in C is a collection of elements of the same type stored in contiguous memory locations. It is like a list where each element can be accessed by its index.
Click to reveal answer
beginner
How do you declare a one-dimensional array of 5 integers in C?
You declare it like this: int arr[5]; This creates an array named arr that can hold 5 integers.
Click to reveal answer
beginner
How do you access the third element of an array named arr?
You access it using the index 2: arr[2]. Remember, array indexes start at 0, so the first element is arr[0].
Click to reveal answer
intermediate
What happens if you try to access an array element outside its declared size?
Accessing outside the array size causes undefined behavior. It may read or write memory it shouldn't, leading to bugs or crashes.
Click to reveal answer
beginner
How can you initialize a one-dimensional array with values at the time of declaration?
You can write: int arr[3] = {10, 20, 30}; This sets the first element to 10, second to 20, and third to 30.
Click to reveal answer
What is the index of the first element in a C array?
A0
B1
C-1
DDepends on the array size
Which of the following declares an array of 10 floats?
Aint arr[10];
Bfloat arr[10];
Cfloat arr;
Dfloat arr(10);
What will happen if you write to arr[5] when arr is declared as int arr[5];?
AIt causes undefined behavior
BIt writes to the last element safely
CIt throws a compile-time error
DIt automatically resizes the array
How do you initialize an array with all zeros in C?
Aint arr[5] = NULL;
Bint arr[5] = 0;
Cint arr[5]; // automatically zeroed
Dint arr[5] = {0};
Which statement correctly accesses the last element of int arr[7];?
Aarr[-1]
Barr[7]
Carr[6]
Darr[0]
Explain what a one-dimensional array is and how you use it in C.
Think of it like a row of boxes where each box holds a value.
You got /4 concepts.
    Describe how to declare, initialize, and access elements in a one-dimensional array in C.
    Remember the array size and zero-based indexing.
    You got /4 concepts.