Chapter 6: MCQs on Pointers in C++ | C++ Programming

Mastering C++ Pointers: Comprehensive MCQs for Enhanced Understanding
Delve into essential C++ pointer concepts with this 30-question MCQ set. Topics include pointers’ basics, pointer variables, arithmetic, arrays, and function pointers—ideal for students and programmers aiming to deepen their skills.


MCQs

1. What does a pointer store in C++?

  • A. The value of a variable
  • B. The address of a variable
  • C. The data type of a variable
  • D. The name of a variable

2. Which symbol is used to declare a pointer variable in C++?

  • A. @
  • B. $
  • C. &
  • D. *

3. What is the output of *ptr if ptr is a pointer to an integer variable x?

  • A. The address of x
  • B. The value stored in x
  • C. The data type of x
  • D. The size of x

4. How do you declare a pointer to an integer in C++?

  • A. int *ptr;
  • B. int ptr*;
  • C. int &ptr;
  • D. int ptr&;

5. Which operator is used to access the address of a variable in C++?

  • A. *
  • B. &
  • C. @
  • D. #

6. If ptr is a pointer to int, what does ptr++ do?

  • A. Increases the value of ptr by 1
  • B. Increases the address in ptr by 1
  • C. Moves the pointer to the next integer position
  • D. Moves the pointer to the previous integer position

7. What will happen if a pointer with NULL value is dereferenced?

  • A. It returns 0
  • B. It throws a compile-time error
  • C. It causes a segmentation fault
  • D. It initializes the pointer

8. Which of the following is the correct way to initialize a pointer variable in C++?

  • A. int *ptr = NULL;
  • B. int ptr = NULL;
  • C. int &ptr = NULL;
  • D. int ptr;

9. If ptr points to an integer variable, what is the correct way to change the value of the variable it points to?

  • A. ptr = 20;
  • B. *ptr = 20;
  • C. &ptr = 20;
  • D. ptr* = 20;

10. What is the term used when a pointer points to the memory that is no longer allocated?

  • A. Null pointer
  • B. Dangling pointer
  • C. Wild pointer
  • D. Constant pointer

11. How do pointers and arrays relate in C++?

  • A. Pointers are the same as arrays
  • B. An array name acts like a constant pointer
  • C. Arrays cannot be used with pointers
  • D. Pointers cannot point to arrays

12. If arr is an array, which of the following expressions is equivalent to arr[2]?

  • A. *(arr+2)
  • B. arr*2
  • C. arr(2)
  • D. *arr[2]

13. Which type of pointer points to the first element of an array?

  • A. Array pointer
  • B. Constant pointer
  • C. Null pointer
  • D. Pointer to an array

14. What is pointer arithmetic in C++?

  • A. Performing arithmetic operations with integers
  • B. Performing operations on addresses stored in pointers
  • C. Changing the data type of a pointer
  • D. Assigning values to pointers

15. Which operation is valid for pointer arithmetic?

  • A. Adding two pointers
  • B. Subtracting an integer from a pointer
  • C. Dividing a pointer by an integer
  • D. Multiplying a pointer by an integer

16. What does the expression *(ptr + i) represent when ptr points to the start of an array?

  • A. ith value in the array
  • B. Address of ith element
  • C. The entire array
  • D. None of the above

17. How do you define a pointer to a function that takes no arguments and returns an integer?

  • A. int (*fptr)();
  • B. int fptr();
  • C. int *fptr();
  • D. int fptr(*)();

18. Which of the following statements is true about pointers to functions?

  • A. A pointer cannot point to a function
  • B. A function cannot return a pointer
  • C. A function pointer can store the address of a function
  • D. Function pointers cannot be assigned

19. What is the purpose of a const pointer?

  • A. To allow the pointer address to be modified
  • B. To prevent modification of the pointer address
  • C. To prevent modification of the pointed value
  • D. Both B and C

20. Which keyword is used to create a pointer that cannot be changed?

  • A. const
  • B. static
  • C. void
  • D. new

21. What is the output of the following code if ptr points to an array int arr[] = {1, 2, 3}; and cout << *ptr; is executed?

  • A. 0
  • B. 1
  • C. Address of arr
  • D. The whole array

22. Which of the following types of pointers are automatically assigned to avoid dereferencing issues?

  • A. Wild pointers
  • B. Null pointers
  • C. Constant pointers
  • D. Uninitialized pointers

23. When is a pointer said to be uninitialized?

  • A. When it is set to NULL
  • B. When it points to an unknown memory location
  • C. When it is assigned a valid address
  • D. When it points to 0

24. What will be the result if ++ptr is used on a pointer pointing to an array?

  • A. Pointer moves to the next array element
  • B. Pointer moves to the previous array element
  • C. Pointer value decreases by 1
  • D. None of the above

25. Which statement correctly defines a void pointer?

  • A. void *ptr;
  • B. int void *ptr;
  • C. *void ptr;
  • D. void ptr;

26. How do you call a function using a function pointer in C++?

  • A. *fptr();
  • B. fptr->();
  • C. (*fptr)();
  • D. *fptr;

27. Which of the following statements about pointers is true?

  • A. Pointers cannot be compared
  • B. A pointer cannot be NULL
  • C. The address of a pointer can be obtained using &
  • D. Pointers cannot be reassigned

28. How can you declare a pointer to an array in C++?

  • A. int *arr_ptr[];
  • B. int (*arr_ptr)[];
  • C. int arr_ptr[];
  • D. int arr_ptr;

29. Which of the following is a valid usage of delete in C++?

  • A. delete ptr[];
  • B. delete ptr;
  • C. delete *ptr;
  • D. delete ptr; ptr = NULL;

30. Which of the following expressions is used to assign the address of variable a to pointer ptr?

  • A. ptr = a;
  • B. ptr = &a;
  • C. ptr = *a;
  • D. ptr = *&a;

Answer Key

QNoAnswer
1B. The address of a variable
2D. *
3B. The value stored in x
4A. int *ptr;
5B. &
6C. Moves the pointer to the next integer position
7C. It causes a segmentation fault
8A. int *ptr = NULL;
9B. *ptr = 20;
10B. Dangling pointer
11B. An array name acts like a constant pointer
12A. *(arr+2)
13D. Pointer to an array
14B. Performing operations on addresses stored in pointers
15B. Subtracting an integer from a pointer
16A. ith value in the array
17A. int (*fptr)();
18C. A function pointer can store the address of a function
19D. Both B and C
20A. const
21B. 1
22B. Null pointers
23B. When it points to an unknown memory location
24A. Pointer moves to the next array element
25A. void *ptr;
26C. (*fptr)();
27C. The address of a pointer can be obtained using &
28B. int (*arr_ptr)[];
29B. delete ptr;
30B. ptr = &a;

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top