Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 13
Q201:
How should you pass a two-dimensional array to a function in C++?
A. Only specify the array name
B. Specify the array name and the number of rows
C. Specify the array name and the number of columns
D. Only specify the number of rows
Correct Answer:
C
Chapter: 13
Q202:
What is a key consideration when implementing the findUnluckies function?
A. Ensure it operates in constant time
B. Ensure it correctly identifies employees with lesser take-home pay
C. Ensure it handles large arrays efficiently
D. Ensure it only processes the top salaries
Correct Answer:
B
Chapter: 13
Q203:
Why might a global variable be used in the salary calculation program?
A. To avoid passing variables between functions
B. To store intermediate calculation results
C. To keep track of the number of employees globally
D. To simplify the function implementations
Correct Answer:
A
Chapter: 13
Q204:
What is the purpose of initializing the lucky array to zero?
A. To mark all employees as unlucky initially
B. To mark all employees as lucky initially
C. To avoid accessing uninitialized elements
D. To ensure all elements are zeroed before processing
Correct Answer:
C
Chapter: 14
Q205:
What does a pointer store in C++?
A. The value of a variable
B. The memory address of a variable
C. The data type of a variable
D. The name of a variable
Correct Answer:
B
Chapter: 14
Q206:
What is the purpose of the address operator (&) in C++?
A. To obtain the memory address of a variable
B. To obtain the value stored in a variable
C. To declare a pointer
D. To perform a logical AND operation
Correct Answer:
A
Chapter: 14
Q207:
How do you declare a pointer to an integer in C++?
A. int *ptr
B. int ptr*
C. int ptr
D. int * ptr
Correct Answer:
A
Chapter: 14
Q208:
What does *ptr represent when ptr is a pointer variable?
A. The address of ptr
B. The value stored at the memory location pointed to by ptr
C. The type of data ptr points to
D. The size of the memory location pointed to by ptr
Correct Answer:
B
Chapter: 14
Q209:
What will be the result of the statement *ptr = 10; if ptr is a pointer to an integer?
A. The value 10 is stored at the memory location ptr points to
B. The address of the memory location pointed to by ptr
C. The value of ptr is set to 10
D. The pointer ptr is assigned a new address
Correct Answer:
A
Chapter: 14
Q210:
What is the output of *ptr + 2 where *ptr is 10?
A. 8
B. 10
C. 12
D. 14
Correct Answer:
C
Chapter: 14
Q211:
How do you initialize a pointer to a variable in C++?
A. ptr = 0
B. ptr = NULL
C. ptr = &var
D. ptr = var
Correct Answer:
C
Chapter: 14
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
Correct Answer:
B
Chapter: 14
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
Correct Answer:
B
Chapter: 14
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
Correct Answer:
A
Chapter: 14
Q215:
How do you declare a pointer to a character in C++?
A. char *ptr
B. char ptr*
C. char ptr
D. char * ptr
Correct Answer:
A
Chapter: 14
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
Correct Answer:
A
Chapter: 14
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
Correct Answer:
B
Chapter: 14
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
Correct Answer:
B
Chapter: 14
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
Correct Answer:
B
Chapter: 14
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
Correct Answer:
A