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?

Beginner
A To store a floating-point number B To store a string literal C To store the memory address of a variable D To store a character value
Show 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?

Beginner
A * B -> C & D .
Show 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?

Beginner
A Multiplies the variable by 2 B Returns the value of the variable C Returns the memory address of the variable D Dereferences the pointer
Show 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`?

Beginner
A The address of p B The address of x C Undefined D 10
Show 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?

Beginner
A A pointer that points to a valid memory location B A pointer that points to a variable with value 0 C A pointer that points to no valid memory location D A pointer that cannot be dereferenced
Show 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.

Beginner
A True B False
Show 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.

Beginner
A True B False
Show 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); ```

Intermediate
A 5 B Compilation error C Address of a D 8
Show 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?

Intermediate
A It causes undefined behavior, often a crash B It automatically allocates memory C It returns the address of the null pointer D It returns 0
Show 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?

Intermediate
A Multiplying a pointer by an integer B Performing arithmetic operations on the value pointed to C Performing arithmetic operations on the pointer's address D Adding two pointers together
Show 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?

Intermediate
A The next byte after p B The address of the next integer element C The address of the first element D The value of the next integer element
Show 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?

Intermediate
A Arrays are always pointers B An array name is a constant pointer to its first element C Arrays store pointers D Pointers cannot be used with arrays
Show 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?

Intermediate
A A pointer that points to a null value B A pointer that stores the address of another pointer C A pointer that points to a constant D A pointer that points to a function
Show 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?

Intermediate
A Pass the variable name only B Pass the address of the variable using & C Pass a copy of the variable D Pass the value of the variable
Show 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?

Intermediate
A They eliminate the need for variables B They allow direct memory access and efficient manipulation C They automatically manage memory D They make the code shorter
Show 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?

Intermediate
A Using the delete keyword B Using the realloc() function C Using the malloc() function D Using the free() function
Show 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?

Advanced
A A pointer that points to a variable B A function that takes a pointer as an argument C A pointer that points to a function's code D A function that returns a pointer
Show 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?

Advanced
A A pointer that points to a constant B A pointer that points to a null value C A pointer that points to a valid variable D A pointer that points to memory that has been freed or deallocated
Show 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.

Make your own

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