The address operator (&) gives the memory address of a variable. It tells where the variable is stored in memory.
Click to reveal answer
beginner
What is the purpose of the dereference operator (*) in C?
The dereference operator (*) accesses the value stored at a given memory address (pointer). It lets you read or change the value the pointer points to.
Click to reveal answer
beginner
Explain the difference between a pointer and a normal variable.
A normal variable stores a value directly. A pointer stores the address of another variable, not the value itself.
Click to reveal answer
beginner
Given int x = 10; int *p = &x;, what does *p represent?
*p represents the value stored at the address held by p. Here, it is the value of x, which is 10.
Click to reveal answer
intermediate
Why is it important to use the dereference operator carefully?
Using the dereference operator on an invalid or uninitialized pointer can cause errors or crashes because it tries to access memory that may not belong to your program.
Click to reveal answer
What does the & operator do in C?
AReturns the address of a variable
BDereferences a pointer
CDeclares a pointer variable
DAssigns a value to a variable
✗ Incorrect
The & operator returns the memory address of a variable.
If int *p = &x;, what does *p mean?
AThe address of x
BA new pointer
CThe value of x
DThe size of x
✗ Incorrect
*p accesses the value stored at the address pointed to by p, which is the value of x.
Which operator is used to get the value stored at a pointer's address?
A&
B*
C->
D%
✗ Incorrect
The * operator dereferences a pointer to get the value at the address.
What happens if you dereference a pointer that is not initialized?
AThe program may crash or behave unpredictably
BYou get the value zero
CIt automatically initializes the pointer
DNothing happens
✗ Incorrect
Dereferencing an uninitialized pointer can cause crashes or undefined behavior.
Which of the following is a correct way to declare a pointer to an int?
Apointer int p;
Bint p;
Cint &p;
Dint *p;
✗ Incorrect
int *p; declares a pointer to an int.
Describe how the address (&) and dereference (*) operators work together with pointers in C.
Think about how you find where something is and then how you look inside it.
You got /3 concepts.
Explain why using the dereference operator on an invalid pointer is dangerous.
Consider what happens if you try to open a door that doesn't exist.
You got /3 concepts.
Practice
(1/5)
1. What does the & operator do in C?
easy
A. It gives the memory address of a variable.
B. It multiplies two numbers.
C. It dereferences a pointer to get the value.
D. It declares a pointer variable.
Solution
Step 1: Understand the & operator
The & operator is used to get the address of a variable in memory.
Step 2: Differentiate from other operators
It does not multiply, dereference, or declare pointers; those are different operations.
Final Answer:
It gives the memory address of a variable. -> Option A
Quick Check:
& means address-of [OK]
Hint: Remember & means 'address of' variable [OK]
Common Mistakes:
Confusing & with multiplication operator
Thinking & dereferences a pointer
Mixing & with pointer declaration
2. Which of the following is the correct way to declare a pointer to an integer in C?
easy
A. *int ptr;
B. int &ptr;
C. int ptr*;
D. int *ptr;
Solution
Step 1: Recall pointer declaration syntax
In C, a pointer to an int is declared as int *ptr; where * indicates pointer type.
Step 2: Check other options for syntax errors
int &ptr; is invalid in C (it's C++ reference), int ptr*; and *int ptr; are incorrect syntax.
Final Answer:
int *ptr; -> Option D
Quick Check:
Pointer declaration uses * before variable name [OK]
Hint: Pointer declaration: type *name; [OK]
Common Mistakes:
Using & instead of * for pointers
Placing * after variable name incorrectly
Confusing C++ references with pointers
3. What is the output of this code?
int x = 10;
int *p = &x;
printf("%d", *p);
medium
A. 10
B. The memory address of x
C. Garbage value
D. Compilation error
Solution
Step 1: Understand pointer assignment
Pointer p stores the address of x using &x.
Step 2: Dereference pointer to get value
*p accesses the value at the address stored in p, which is 10.
Final Answer:
10 -> Option A
Quick Check:
*p gives value at address [OK]
Hint: *p gives value stored at pointer address [OK]
Common Mistakes:
Printing pointer variable instead of dereferenced value
Confusing & and * operators
Expecting address instead of value
4. Identify the error in this code snippet:
int x = 5;
int *p;
*p = x;
printf("%d", *p);
medium
A. Incorrect use of & operator.
B. Pointer p is not initialized before dereferencing.
C. Variable x is not declared.
D. Missing semicolon after declaration.
Solution
Step 1: Check pointer initialization
Pointer p is declared but not assigned an address before *p = x;.