Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q211: How do you initialize a pointer to a variable in C++?
- A: ptr = 0
- B: ptr = NULL
- C: ptr = &var
- D: ptr = var
View Answer
C
Q212: What is a null pointer in C++?
- A: A pointer that points to an arbitrary address
- B: A pointer that points to nothing
- C: A pointer with an undefined value
- D: A pointer that holds the address of another pointer
View Answer
B
Q213: What does const int *ptr indicate in a pointer declaration?
- A: ptr is a constant pointer to an integer
- B: ptr is a pointer to a constant integer
- C: ptr is a constant variable pointing to an integer
- D: ptr is an integer variable with a constant value
View Answer
B
Q214: What is the main advantage of using pointers for function calls?
- A: To pass large amounts of data efficiently
- B: To change the function’s return type
- C: To make function calls faster
- D: To avoid using global variables
View Answer
A
Q215: How do you declare a pointer to a character in C++?
- A: char *ptr
- B: char ptr*
- C: char ptr
- D: char * ptr
View Answer
A
Q216: What does the statement ptr = &x; accomplish in C++?
- A: Assigns the address of x to the pointer ptr
- B: Assigns the value of x to the pointer ptr
- C: Initializes x with the address of ptr
- D: Changes the value of x to ptr
View Answer
A
Q217: What happens if you pass an array to a function in C++?
- A: A copy of the array is passed
- B: The function gets the address of the array
- C: The function receives each element of the array separately
- D: The function creates a new array
View Answer
B
Q218: How does the swap function use pointers to exchange values?
- A: By directly swapping the values of the variables
- B: By passing the addresses of the variables and swapping the values at those addresses
- C: By copying values to a temporary variable and swapping them
- D: By using temporary arrays to hold values
View Answer
B
Q219: What is the purpose of the const keyword in const int *ptr?
- A: To make ptr immutable
- B: To make the value pointed to by ptr immutable
- C: To restrict ptr to only point to const variables
- D: To make ptr itself constant
View Answer
B
Q220: What is the main difference between int *const ptr and const int *ptr?
- A: int *const ptr is a constant pointer, while const int *ptr is a pointer to a constant integer
- B: int *const ptr is a pointer to a constant integer, while const int *ptr is a constant pointer
- C: int *const ptr is a constant pointer, while const int *ptr is a mutable pointer
- D: Both declarations are equivalent in functionality
View Answer
A