0
0
Cprogramming~5 mins

Common array operations - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an array in C?
An array in C is a collection of elements of the same type stored in contiguous memory locations. It allows you to store multiple values under a single name and access them using an index.
Click to reveal answer
beginner
How do you access the third element of an array named arr?
You access it using arr[2] because array indexing starts at 0 in C.
Click to reveal answer
intermediate
How do you find the length of a statically declared array in C?
Use sizeof(arr) / sizeof(arr[0]) to get the number of elements in the array.
Click to reveal answer
intermediate
How can you copy elements from one array to another in C?
You can copy elements using a loop to assign each element individually, for example:<br>
for(int i = 0; i < n; i++) { dest[i] = src[i]; }
Click to reveal answer
advanced
What is the result of accessing an array out of its bounds in C?
Accessing out of bounds leads to undefined behavior. It can cause crashes or incorrect data because C does not check array bounds.
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 correctly declares an array of 5 integers?
Aint arr[5];
Bint arr();
Cint arr;
Darray int arr[5];
How do you get the number of elements in a statically declared array arr?
Acount(arr)
Bsizeof(arr) / sizeof(arr[0])
Carr.length
Dlength(arr)
What happens if you access arr[10] when arr has only 5 elements?
AReturns last element
BReturns 0
CCompiler error
DUndefined behavior
Which loop is commonly used to iterate over all elements of an array?
Ado-while loop
Bwhile loop
Cfor loop
Dswitch statement
Explain how to declare, initialize, and access elements of an array in C.
Think about how you store multiple values and get each one by its position.
You got /3 concepts.
    Describe common operations you can perform on arrays in C and any risks involved.
    Consider what you do with a list of items and what can go wrong if you go outside the list.
    You got /4 concepts.