0
0
Cprogramming~5 mins

Pointers and arrays in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a pointer in C?
A pointer is a variable that stores the memory address of another variable. It allows direct access to memory locations.
Click to reveal answer
beginner
How are arrays and pointers related in C?
The name of an array acts like a pointer to its first element. You can use pointers to access array elements by moving through memory.
Click to reveal answer
intermediate
What does the expression *(arr + i) mean when arr is an array?
It means accessing the element at index i of the array arr. It uses pointer arithmetic to move i positions from the start.
Click to reveal answer
beginner
How do you declare a pointer to an integer in C?
You declare it as int *ptr; where ptr can store the address of an integer variable.
Click to reveal answer
intermediate
What happens if you increment a pointer ptr that points to an integer?
Incrementing ptr moves it to point to the next integer in memory, usually increasing the address by the size of an integer (e.g., 4 bytes).
Click to reveal answer
What does the name of an array represent in C?
AA pointer to the last element
BThe address of the first element
CThe value of the first element
DThe total size of the array
Which operator is used to get the value stored at the address a pointer points to?
A* (dereference)
B& (address-of)
C-> (arrow)
D+ (addition)
If int *p = arr; where arr is an array, what does p + 2 point to?
AThe third element
BThe first element
CThe second element
DAn invalid memory location
What is the output of this code snippet?
int arr[3] = {10, 20, 30};
printf("%d", *(arr + 1));
A10
B30
CGarbage value
D20
Which of the following is a valid way to access the first element of an array arr using pointers?
A*(arr + 0)
B*arr
CAll of the above
Darr[0]
Explain how pointers and arrays are connected in C and how you can use pointer arithmetic to access array elements.
Think about how the array name works like a pointer and how adding numbers to pointers moves through the array.
You got /3 concepts.
    Describe what happens in memory when you increment a pointer that points to an integer array.
    Consider how memory addresses change when you move from one element to the next.
    You got /3 concepts.