Kit Library / Computer Science / C Programming / Memory Management

⚡ Topic Learning Kit

Pointers in C Language

English 18 leveled MCQs 20 flashcards 9 games Free

Shared by a Veda learner · 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 Holds an Address, Not a Value

Pointers store addresses, not data.

A pointer is a variable whose value is the memory address of another variable — it 'points to' where the data lives.

↳ Think of a pointer as a label on a locker — it tells you where the data is, not what the data is.

📖 Definition

Declaring and Initializing Pointers

Star declares, ampersand assigns.

↳ The `*` in declaration means 'pointer to'; the `&` gives an address; `*p` dereferences.

⚠️ Common Mistake

Uninitialized Pointers Are Dangerous

Wild pointers crash programs silently.

↳ A pointer without a target is a loaded gun — initialize to NULL or a valid address.

⚖️ Comparison

Pointer vs. Variable: What's the Difference?

Same memory, two different views.

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

💻 Code Example

Pointers Let Functions Modify Caller's Data

Pass by pointer, change the original.

C passes arguments by value, so a function normally gets a copy. Passing a pointer lets the function modify the original variable.

↳ To change a variable inside a function, pass its address — not its value.

💡 Key Idea

Arrays and Pointers Are Closely Linked

An array name is almost a pointer.

↳ Array indexing is just pointer arithmetic in disguise.

⚙️ Process

How Pointer Arithmetic Works

Add 1, jump by type size.

↳ Pointer + n moves n elements forward, not n bytes.

🚫 Warning

Dangling Pointers: Pointing to Freed Memory

Freed memory is not safe memory.

↳ Free, then null — always in that order.

✅ Best Practice

Safe Pointer Habits

Small habits, fewer crashes.

↳ Most pointer bugs come from missing initialization or missing cleanup.

🌍 Real World

Where Pointers Power Real Systems

Pointers run the systems you use.

↳ Every dynamic data structure in C is a pointer structure underneath.

🎯 Exam Tip

Exam Favorite: Output Prediction

Trace addresses, not just values.

↳ In pointer output questions, track what each pointer points to at each line.

🧠 Memory Trick

Remember the Two Symbols

Ampersand asks, star answers.

`&` = 'address of' (ask where it lives). `*` = 'value at' (go there and read).

↳ & gives an address; * uses an address.

💡 Interview Tip

Interview Classic: Pointer vs. Reference

One can be NULL, one cannot.

↳ In C, pointers are the only way to refer to another variable indirectly.

❓ Did You Know

All Pointers Are the Same Size

Char pointer, int pointer — same bytes.

On a given system, every pointer type occupies the same number of bytes (e.g., 8 bytes on 64-bit). The type only tells the compiler how to interpret the pointed-to data and how far arithmetic moves.

↳ Pointer size is fixed per architecture; the type controls interpretation, not size.

🛠️ Application

Pointers Enable Dynamic Memory

Size decided at runtime.

`malloc` returns a pointer to heap memory whose size is decided at runtime — impossible with fixed-size arrays.

↳ Dynamic memory = pointers + malloc/free; always check for NULL and free when done.

Smart notes

What you'll study, topic by topic

1

Pointers in C Language

20 min

Pointers are variables that store memory addresses, giving C programs direct access to memory. They enable efficient array handling, dynamic memory, and function-based data modification, but demand careful handling to av…

  • A pointer is a variable that holds a memory address.
  • The `&` operator returns the address of a variable.
  • The `*` operator dereferences a pointer to access the value at that address.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

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

Warm-up · 6 questions

Q1. What is a pointer in C?

Beginner
A A data type that stores text
B A keyword that frees memory
C A function that allocates memory
D A variable that stores a memory address

Answers and explanations are in the Veda app.

Q2. Which operator returns the address of a variable?

Beginner
A `*`
B `&`
C `->`
D `%`

Answers and explanations are in the Veda app.

Q3. What does the `*` operator do when applied to a pointer?

Beginner
A Multiplies the pointer by two
B Dereferences it to access the value at that address
C Returns the address of the pointer itself
D Frees the memory the pointer references

Answers and explanations are in the Veda app.

Q4. Which line correctly declares a pointer to an int?

Beginner
A `int p*;`
B `pointer int p;`
C `int &p;`
D `int *p;`

Answers and explanations are in the Veda app.

Q5. In C, an array name in most expressions behaves like:

Beginner
A A pointer to its last element
B A null pointer
C A copy of the whole array
D A pointer to its first element

Answers and explanations are in the Veda app.

Q6. In C, an array name is not a pointer but decays to a pointer to its first element in most expressions.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Building up · 7 questions

Q7. If `int` is 4 bytes, how far does `p + 1` advance for an `int *p`?

Intermediate
A 1 byte
B 4 bytes
C 8 bytes
D 2 bytes

Answers and explanations are in the Veda app.

Q8. Why does `scanf("%d", &x);` need the `&`?

Intermediate
A `&` frees memory before reading
B `scanf` needs the value of `x` to compare
C `scanf` needs the address to store the input into `x`
D `&` converts the input to a string

Answers and explanations are in the Veda app.

Q9. What is the effect of `void increment(int *n) { (*n)++; }` called as `increment(&x);`?

Intermediate
A The program crashes because `x` is not a pointer
B `x` is incremented in the caller
C `x` becomes a pointer
D A copy of `x` is incremented and discarded

Answers and explanations are in the Veda app.

Q10. What does `malloc` return on success?

Intermediate
A A null pointer always
B A pointer to stack memory
C The size of the allocated block
D A pointer to heap memory

Answers and explanations are in the Veda app.

Q11. What is a dangling pointer?

Intermediate
A A pointer that points to the stack
B A pointer that has never been declared
C A pointer that still holds the address of memory already freed
D A pointer that is always `NULL`

Answers and explanations are in the Veda app.

Q12. What does `int **pp;` declare?

Intermediate
A A pointer to a pointer to an int
B An int with two stars in its name
C Two separate int pointers
D A pointer to an array of ints

Answers and explanations are in the Veda app.

Q13. What is wrong with `int *a, b;` if you wanted two pointers?

Intermediate
A Neither `a` nor `b` is a pointer
B Only `a` is a pointer; `b` is an int
C Both `a` and `b` are pointers
D The compiler rejects the line

Answers and explanations are in the Veda app.

Topper level · 5 questions

Q14. Why must you check a pointer for `NULL` before dereferencing?

Advanced
A `NULL` pointers automatically allocate memory
B Checking converts the pointer to an int
C Dereferencing `NULL` is undefined behavior and typically crashes
D `NULL` pointers always point to valid stack memory

Answers and explanations are in the Veda app.

Q15. What is the difference between `*p = &x;` and `p = &x;`?

Advanced
A Both are correct and equivalent
B Both are type errors
C `*p = &x;` is a type error; `p = &x;` is correct
D `p = &x;` is a type error; `*p = &x;` is correct

Answers and explanations are in the Veda app.

Q16. Which statement about `sizeof(arr)` versus `sizeof(ptr)` is correct?

Advanced
A `sizeof(ptr)` gives total array size; `sizeof(arr)` gives pointer size
B `sizeof` cannot be applied to arrays
C `sizeof(arr)` gives total array size; `sizeof(ptr)` gives pointer size
D Both always give the same value

Answers and explanations are in the Veda app.

Q17. Given the following code snippet, what will be the output when `printf("%d", **pp);` is executed? ```c int x = 5; int *p = &x; int **pp = &p; ```

Advanced
A Undefined behavior
B Address of p
C 5
D Address of x

Answers and explanations are in the Veda app.

Q18. Consider the following code segment. What will happen when `free(arr);` is called? ```c int *arr = malloc(10 * sizeof(int)); if (arr != NULL) { for (int i = 0; i < 10; i++) { arr[i] = i; } } free(arr); arr[0] = 100; // What is the consequence of this line? ```

Advanced
A The program will run without issues.
B It will cause a memory leak.
C The program will crash.
D The value 100 will be assigned to arr[0].

Answers and explanations are in the Veda app.

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.