Bird
Raised Fist0
Cprogramming~5 mins

Pointers and arrays in C - Cheat Sheet & Quick Revision

Choose your learning style10 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.

      Practice

      (1/5)
      1. What does a pointer to an array in C typically store?
      easy
      A. The address of the first element of the array
      B. The total number of elements in the array
      C. The sum of all elements in the array
      D. The value of the last element in the array

      Solution

      1. Step 1: Understand pointer basics

        A pointer stores a memory address, not values or counts.
      2. Step 2: Pointer to array points to first element

        In C, a pointer to an array points to the first element's address.
      3. Final Answer:

        The address of the first element of the array -> Option A
      4. Quick Check:

        Pointer = first element address [OK]
      Hint: Pointers hold addresses, not values or counts [OK]
      Common Mistakes:
      • Thinking pointer stores array size
      • Confusing pointer with array value
      • Assuming pointer stores last element
      2. Which of the following is the correct way to declare a pointer to an integer array in C?
      easy
      A. int ptr[];
      B. int *ptr;
      C. int &ptr;
      D. int ptr*;

      Solution

      1. Step 1: Recall pointer declaration syntax

        In C, a pointer to int is declared as int *ptr;
      2. Step 2: Check other options for syntax errors

        int ptr[] declares an array, not a pointer; int &ptr is invalid in C; int ptr* is incorrect syntax.
      3. Final Answer:

        int *ptr; -> Option B
      4. Quick Check:

        Pointer syntax uses * before variable [OK]
      Hint: Pointer declaration uses * before variable name [OK]
      Common Mistakes:
      • Using array syntax instead of pointer
      • Confusing C++ reference (&) with pointer
      • Placing * after variable name incorrectly
      3. What is the output of the following C code?
      int arr[] = {10, 20, 30};
      int *p = arr;
      printf("%d", *(p + 1));
      medium
      A. 10
      B. 30
      C. Garbage value
      D. 20

      Solution

      1. Step 1: Understand pointer arithmetic

        p points to arr[0], so p + 1 points to arr[1].
      2. Step 2: Dereference pointer at p + 1

        *(p + 1) gives value at arr[1], which is 20.
      3. Final Answer:

        20 -> Option D
      4. Quick Check:

        *(p+1) = arr[1] = 20 [OK]
      Hint: Pointer + 1 moves to next array element [OK]
      Common Mistakes:
      • Confusing *(p+1) with *p
      • Assuming pointer arithmetic adds 1 byte
      • Expecting arr[0] value instead
      4. Identify the error in this C code snippet:
      int arr[3] = {1, 2, 3};
      int *p = arr + 3;
      printf("%d", *p);
      medium
      A. Missing semicolon after array declaration
      B. Array size is incorrect
      C. Pointer points outside array bounds causing undefined behavior
      D. Pointer declaration syntax is wrong

      Solution

      1. Step 1: Analyze pointer assignment

        arr + 3 points one element past the last array element (out of bounds).
      2. Step 2: Dereferencing out-of-bounds pointer

        *p accesses invalid memory, causing undefined behavior.
      3. Final Answer:

        Pointer points outside array bounds causing undefined behavior -> Option C
      4. Quick Check:

        Pointer out of array range = error [OK]
      Hint: Pointer must stay within array limits [OK]
      Common Mistakes:
      • Ignoring pointer out-of-bounds access
      • Thinking array size is wrong
      • Confusing pointer syntax errors
      5. Given the code below, what will be printed?
      int arr[] = {5, 10, 15, 20};
      int *p = arr;
      for(int i = 0; i < 4; i++) {
          printf("%d ", *(p + i));
      }
      hard
      A. 5 10 15 20
      B. 20 15 10 5
      C. 5 5 5 5
      D. Compilation error

      Solution

      1. Step 1: Understand the loop and pointer arithmetic

        Loop runs i from 0 to 3, *(p + i) accesses arr[i].
      2. Step 2: Print each element in order

        Values printed are arr[0]=5, arr[1]=10, arr[2]=15, arr[3]=20.
      3. Final Answer:

        5 10 15 20 -> Option A
      4. Quick Check:

        Pointer + i accesses arr[i] in order [OK]
      Hint: Pointer + i accesses array element i [OK]
      Common Mistakes:
      • Assuming reverse order print
      • Printing same element repeatedly
      • Expecting syntax error
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard