Kit Library / Computer Science / C Programming / Memory Management

⚡ Topic Learning Kit

Pointers in C Language with Examples

English 21 leveled MCQs 20 flashcards 9 games Free

Shared by a Veda teacher · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

A Pointer Stores an Address, Not a Value

Pointers point — they don't hold the value.

A pointer is a variable whose value is the memory address of another variable. It lets you access that variable indirectly.

↳ Pointer = address holder; * reads/writes the value at that address.

📖 Definition

Declaring and Initializing a Pointer

Star declares, ampersand assigns.

↳ Use `type *name = &variable;` to declare and point in one line.

💻 Code Example

Full Working Example: Read and Modify via Pointer

Change x without touching x.

Writing `*p = 20` changes the value at the address p holds — which is x itself.

↳ Dereferencing on the left side of `=` writes to the original variable.

⚖️ Comparison

Variable vs Pointer: What's Stored

Value vs address — know the difference.

↳ A variable holds data; a pointer holds where the data lives.

⚙️ Process

How Dereferencing Works Step-by-Step

Follow the arrow to the value.

↳ Dereferencing follows the stored address to reach the original variable.

⚠️ Common Mistake

Uninitialized Pointers Are Dangerous

Wild pointers crash programs.

↳ Never dereference a pointer that doesn't point to valid memory.

⚠️ Common Mistake

Don't Confuse `*p = &x` with `p = &x`

One star changes everything.

↳ Assign addresses to the pointer itself (no star); use star only to reach the value.

🛠️ Application

Why C Uses Pointers: Swap Two Numbers

Swap without return values.

Passing addresses lets a function modify the caller's variables directly.

↳ Pointers enable functions to modify caller data — a key C pattern.

⭐ Important Fact

Pointer Size Is Fixed per Platform

All pointers are the same size.

On a 64-bit system, every pointer (int*, char*, float*) is typically 8 bytes; on 32-bit systems, 4 bytes — regardless of the type it points to.

↳ Pointer size depends on the architecture, not the pointed-to type.

💡 Key Idea

Pointers and Arrays Are Closely Linked

An array name is basically an address.

`arr[i]` is equivalent to `*(arr + i)` — array indexing is pointer arithmetic in disguise.

↳ Array name decays to a pointer to its first element.

⚙️ Process

Pointer Arithmetic: Move by Type Size

p+1 doesn't mean +1 byte.

↳ Pointer arithmetic scales by the size of the pointed-to type.

🚫 Warning

NULL vs Dangling Pointers

Two ways pointers go bad.

↳ Check for NULL; never use a pointer after its target is freed.

🎯 Exam Tip

Exam Favorite: Output of Pointer Code

Trace addresses, not just values.

↳ Most pointer exam questions test whether you can trace address vs value.

🧠 Memory Trick

Remember: & = 'Address Of', * = 'Value At'

Ampersand asks, star answers.

`&` = Address Of (A&O). `*` = Value At (VA). Say it aloud: 'A&O gives the address, VA gives the value.'

↳ & gets the address; * gets the value at that address.

✅ Best Practice

Always Initialize and Check Pointers

Safe pointers save hours of debugging.

↳ Disciplined initialization prevents most pointer bugs.

Smart notes

What you'll study, topic by topic

1

Pointers in C Language with Examples

18 min

Pointers are variables that store the memory address of another variable. They are a core feature of C that enables direct memory access, efficient array handling, dynamic memory, and function-level data sharing. This ki…

  • A **pointer** is a variable that stores a memory address, not a data value.
  • Declaration syntax: `int *p;` means *p is a pointer to int*.
  • The `&` operator returns the address of a variable.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 21 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 8 questions

Q1. Which statement best describes what a pointer stores?

Beginner
A A memory address
B A character constant
C A floating-point value
D A copy of a struct
Show the answer

A · A memory address

A pointer is a variable whose value is a memory address, not a data value.

Q2. Which operator returns the address of a variable?

Beginner
A `->`
B `*`
C `%`
D `&`
Show the answer

D · `&`

The `&` operator is the address-of operator; `*` is the dereference operator.

Q3. If `p = &x`, which expression is equal to `x`?

Beginner
A `*x`
B `*p`
C `&p`
D `p`
Show the answer

B · `*p`

`&` and `*` are inverses: if `p = &x`, then `*p` is the same as `x`.

Q4. What does `int *p;` declare?

Beginner
A `p` is an array of ints
B `p` is a function returning int
C `p` is an `int` variable
D `p` is a pointer to an `int`
Show the answer

D · `p` is a pointer to an `int`

Read `int *p` as 'p is a pointer to int'.

Q5. What does `NULL` mean for a pointer?

Beginner
A It points to nothing
B It points to the stack
C It points to the first array element
D It points to address 0x1
Show the answer

A · It points to nothing

`NULL` is the special constant meaning 'points to nothing'.

Q6. Which pair of functions manages dynamic memory through pointers?

Beginner
A `strlen` and `strcpy`
B `malloc` and `free`
C `fopen` and `fclose`
D `printf` and `scanf`
Show the answer

B · `malloc` and `free`

`malloc` allocates memory and returns a pointer; `free` releases it.

Q7. Which data structures are built from pointers linking nodes?

Beginner
A Only floating-point matrices
B Only character variables
C Linked lists, trees, and graphs
D Only integer arrays
Show the answer

C · Linked lists, trees, and graphs

Linked lists, trees, and graphs are built from pointers linking nodes.

Q8. In C, `arr[i]` is defined to be exactly equivalent to `*(arr + i)`, which is why array indexing and pointer arithmetic are interchangeable.

Beginner
A True
B False
Show the answer

A · True

In C, `arr[i]` is defined to be exactly equivalent to `*(arr + i)`, which is why array indexing and pointer arithmetic are interchangeable.

Building up · 8 questions

Q9. In `int *a, b;`, what is `b`?

Intermediate
A A pointer to pointer
B A plain `int`
C An array of ints
D A pointer to int
Show the answer

B · A plain `int`

The `*` binds to the variable name, so only `a` is a pointer; `b` is a plain int.

Q10. What happens when you dereference a `NULL` pointer?

Intermediate
A It returns 0 safely
B It allocates memory automatically
C Undefined behaviour, usually a crash
D It prints the address
Show the answer

C · Undefined behaviour, usually a crash

Dereferencing `NULL` causes undefined behaviour, typically a crash.

Q11. How does an array name behave when used in an expression?

Intermediate
A It becomes a copy of the whole array
B It becomes the array's length
C It decays to a pointer to its first element
D It becomes a `NULL` pointer
Show the answer

C · It decays to a pointer to its first element

An array name decays to a pointer to its first element, so `arr` behaves like `&arr[0]`.

Q12. Which expression is exactly equivalent to `arr[i]` in C?

Intermediate
A `*(arr + i)`
B `&arr[i]`
C `arr + i`
D `*arr + i`
Show the answer

A · `*(arr + i)`

The C standard defines `arr[i]` as exactly `*(arr + i)`.

Q13. If `p` points to an `int`, how far does `p + 1` advance?

Intermediate
A By 8 bytes always
B By the size of the whole array
C By one `int` (typically 4 bytes)
D By exactly 1 byte
Show the answer

C · By one `int` (typically 4 bytes)

Pointer arithmetic advances in units of the pointed-to type, not bytes.

Q14. Why does C pass a pointer to a function when the function must modify the caller's variable?

Intermediate
A Because C passes arguments by value
B Because pointers are always faster
C Because arrays cannot be passed
D Because functions cannot return values
Show the answer

A · Because C passes arguments by value

C passes arguments by value, so a function gets a copy; passing the address lets it modify the original.

Q15. What is `int **pp`?

Intermediate
A A function returning int
B A pointer to a pointer to int
C A pointer to an int array
D An array of two ints
Show the answer

B · A pointer to a pointer to int

`int **pp` stores the address of another pointer, i.e. a pointer to pointer.

Q16. What is a C string essentially?

Intermediate
A An `int *` ending in 0
B A `void *` with no terminator
C A fixed-size struct
D A `char *` ending in `'\0'`
Show the answer

D · A `char *` ending in `'\0'`

A C string is essentially a `char *` ending in the null character `'\0'`.

Topper level · 5 questions

Q17. Given the following code snippet, what will be the output when the program is executed? ```c #include <stdio.h> void modify(int *p) { *p += 10; } int main(void) { int x = 5; modify(&x); printf("%d\n", x); return 0; } ```

Advanced
A 20
B 10
C 15
D 5
Show the answer

C · 15

The function `modify` takes a pointer to `int`, dereferences it, and adds 10 to the value pointed to. Since `x` is initially 5, after calling `modify(&x)`, `x` becomes 15.

Q18. Consider the following code snippet. What will be the value of `*p` after the execution? ```c #include <stdio.h> #include <stdlib.h> int main(void) { int *p; *p = 42; printf("%d\n", *p); return 0; } ```

Advanced
A 42
B Undefined Behavior
C Segmentation Fault
D 0
Show the answer

C · Segmentation Fault

The pointer `p` is uninitialized and points to a random memory location. Dereferencing it with `*p = 42;` leads to a segmentation fault, as it attempts to write to an invalid address.

Q19. What will be the output of the following code snippet? ```c #include <stdio.h> void swap(int **a, int **b) { int *temp = *a; *a = *b; *b = temp; } int main(void) { int x = 1, y = 2; int *px = &x, *py = &y; swap(&px, &py); printf("%d %d\n", *px, *py); return 0; } ```

Advanced
A 2 1
B 2 2
C 1 2
D 1 1
Show the answer

A · 2 1

The function `swap` takes pointers to pointers and swaps the addresses they point to. After the swap, `px` points to `y` and `py` points to `x`, resulting in the output `2 1`.

Q20. Given the following code, what will be the output of the program? ```c #include <stdio.h> int main(void) { int arr[3] = {1, 2, 3}; int *p = arr + 1; printf("%d\n", *(p - 1) + *(p + 1)); return 0; } ```

Advanced
A 6
B 3
C 5
D 4
Show the answer

D · 4

Here, `p` points to the second element of `arr`, which is `2`. The expression `*(p - 1)` accesses the first element (`1`), and `*(p + 1)` accesses the third element (`3`). Thus, `1 + 3` equals `4`.

Q21. What will happen if the following code is executed? ```c #include <stdio.h> #include <stdlib.h> int main(void) { int *p = malloc(sizeof(int)); *p = 10; free(p); printf("%d\n", *p); return 0; } ```

Advanced
A Segmentation Fault
B 10
C Undefined Behavior
D 0
Show the answer

C · Undefined Behavior

After calling `free(p);`, the memory allocated for `p` is released back to the system. Dereferencing `p` afterwards results in undefined behavior because `p` now points to a deallocated memory.

Flashcards

Tap a card to flip it

20 flashcards in this kit — the app reviews them with spaced repetition so the right card returns on the right day.

Learning games

Play your way through this kit

Every game is built from this kit's own content — scores feed your mastery, so playing counts as studying.

🎮

Word Match

Built from this kit's own content

🎮

True False

Built from this kit's own content

🎮

Memory Match

Built from this kit's own content

🎮

Flashcard Battle

Built from this kit's own content

🎮

Speed Quiz

Built from this kit's own content

🎮

Guess Term

Built from this kit's own content

🎮

Sequence Builder

Built from this kit's own content

🎮

Categorization

Built from this kit's own content

🎮

Revision Battle

Built from this kit's own content

Playable in the app

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.