Pointers in c language: 18 MCQs with answers
All 18 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 7 questions
Q1. What is the primary purpose of a pointer in C?
BeginnerShow answer & explanation
To store the memory address of a variable
A pointer is a variable that holds the memory address of another variable, enabling indirect access.
Q2. Which operator is used to declare a pointer variable in C?
BeginnerShow answer & explanation
*
The asterisk (*) in a declaration indicates that the variable is a pointer to a certain type.
Q3. What does the '&' operator do when applied to a variable?
BeginnerShow answer & explanation
Returns the memory address of the variable
The address-of operator (&) yields the memory address where the variable is stored.
Q4. Given `int x = 10; int *p = &x;` What is the value of `*p`?
BeginnerShow answer & explanation
10
The dereference operator (*) accesses the value stored at the address held by the pointer, which is 10.
Q5. What is a null pointer in C?
BeginnerShow answer & explanation
A pointer that points to no valid memory location
A null pointer (NULL) is a special value that indicates the pointer does not point to any valid memory location.
Q6. A pointer variable stores the memory address of another variable.
BeginnerShow answer & explanation
True
By definition, a pointer holds the address of a variable.
Q7. The dereference operator (*) is used to get the address of a variable.
BeginnerShow answer & explanation
False
The dereference operator (*) accesses the value at the address, while the address-of operator (&) gets the address.
Building up · 9 questions
Q8. What is the output of the following code? ```c int a = 5; int *p = &a; *p = 8; printf("%d", a); ```
IntermediateShow answer & explanation
8
Changing the value at the address pointed to by p modifies the original variable a, so a becomes 8.
Q9. What happens when you dereference a null pointer?
IntermediateShow answer & explanation
It causes undefined behavior, often a crash
Dereferencing a null pointer is undefined behavior and typically results in a segmentation fault or crash.
Q10. What is pointer arithmetic?
IntermediateShow answer & explanation
Performing arithmetic operations on the pointer's address
Pointer arithmetic involves adding or subtracting integers to/from a pointer, which moves the pointer by multiples of the size of the pointed-to type.
Q11. If `int *p` points to an integer array, what does `p + 1` represent?
IntermediateShow answer & explanation
The address of the next integer element
Pointer arithmetic scales by the size of the type, so p+1 points to the next integer in the array.
Q12. What is the relationship between arrays and pointers in C?
IntermediateShow answer & explanation
An array name is a constant pointer to its first element
The name of an array acts like a constant pointer to the first element, and pointer arithmetic can traverse the array.
Q13. What is a pointer to a pointer?
IntermediateShow answer & explanation
A pointer that stores the address of another pointer
A pointer to a pointer (e.g., int **pp) stores the address of a pointer variable, allowing multiple levels of indirection.
Q14. What is the correct way to pass a pointer to a function to modify the original variable?
IntermediateShow answer & explanation
Pass the address of the variable using &
Passing the address (&var) allows the function to dereference the pointer and modify the original variable.
Q15. What is the main advantage of using pointers in C?
IntermediateShow answer & explanation
They allow direct memory access and efficient manipulation
Pointers provide direct memory access, enabling efficient array processing, dynamic memory allocation, and data structures.
Q16. What is the correct way to free dynamically allocated memory in C?
IntermediateShow answer & explanation
Using the free() function
The free() function is used to deallocate memory previously allocated by malloc(), calloc(), or realloc().
Topper level · 2 questions
Q17. What is a function pointer in C?
AdvancedShow answer & explanation
A pointer that points to a function's code
A function pointer stores the address of a function, allowing it to be called indirectly.
Q18. What is a dangling pointer?
AdvancedShow answer & explanation
A pointer that points to memory that has been freed or deallocated
A dangling pointer points to memory that has been freed, leading to undefined behavior when dereferenced.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages