30 C++ MCQs are given below.
Given below are some questions of C++ mcqs along with their answers. Which are the questions asked in the semester examinations or competitive exams of all the universities. This question is for all BCA/B.Tech/CS students
Advertise
(1). Which of the following statements can replace the if-else statement?
- While loop
- Do….. while loop
- For loop
- Conditional operator
4. Conditional Operator
We can also use conditional operator in place of if-else statement, we also know it as ternary operator.
syntax of Ternary Operator or Conditional Operator:
condition ? expression_if_true : expression_if_false
(2). Which of the following is an exit control loop?
- While loop
- Do…. while loop
- For loop
- None of the above
2. Do while loop
While and for loops are entry control loops because they check the condition and execute it. But this is not the case in the Do-While Loop because it first executes the program at least once and then checks the condition.
Syntax While loop:
while (condition) {
// if the condition is true then
// code block to be executed
}
Syntax do-While loop:
do {
// First the code will be executed once and then the condition will be checked.
} while (condition);
(3). Which of the following loops is normally used for a menu-driven program?
- Do… while loop
- For loop
- While loop
- None of the above
3. While loop
While creating a menu, we generally use a while loop because if we put any non-zero value in the condition of the while loop, the same loop will continue to execute until it is exited.
(4). Which of the following loops is the best option when the number of iterations is known?
- While loop
- For loop
- Do… while loop
- All loops require that the iterations be known
2. For loop
(5). Executions of C++ programs start from:
- Void function
- Class
- Main function
- User-defined function
3. Main function
In C++ all programs always start execution from the main function.
Advertise
(6). How many minimum numbers of functions are required to execute a C++ program?
- 1
- 2
- 3
- 4
1. 1
In C++ there must be at least one function to execute the program which is the main function.
(7). Which of the following is a more effective way to call a function with arguments?
- Call by value
- Call by reference
- Call by address
- None of the above
2. Call by reference
Call by reference is the most effective way to call a function with arguments, as it allows the function to directly modify the values of the arguments.
(8). What is the lifetime of a static variable declared in a user-defined function?
- Within the function only
- Within the main function only
- Whole program
- None of the above
3. Whole program
(9). Which of the following statements is correct about inline function?
- A function is substituted at the place of call.
- A function that is called at compile time
- A function that contains only a looping statements
- None of the above
- A function is substituted at the place of call.
(10). Default values for a function are defined
- In function declaration
- In function definition
- During function call
- None of the above
2. In function definition
Advertise
(11). Index of an array starts from:
- 0
- -1
- 2
- 1
1. 0
Indexing of array starts from 0.
(12). In C++ the array name denotes:
- The base address of the array
- The first value of the array
- The last value of the array
- None of the above
1. The base address of the array.
(13). If we create an array “Arr”, which is the correct way to access the first element of the array?
- Arr[0]
- 0[Arr]
- *(Arr+0)
- All of the above
1. Arr[0]
(14). Can we create an array of objects in C++?
- Yes
- No
1. Yes
Yes we can create an array of objects in c++
(15). An array occupies memory Space in:
- Contiguous manner
- Fragmented manner
- Linked list
- None of the above
1. Contiguous manner
An array occupies memory space in contiguous way.
Advertise
(16). How many dimensions are an array in C++?
- 1D array
- 2D array
- 3D array
- No limit
4. No limit
In C++ we can create arrays of any dimension, there is no limit for this.
For Example:
int oneDArray[7]; // 1D array
int twoDArray[5][5]; // 2D array
int threeDArray[3][3][3]; // 3D array
int fourDArray[2][2][2][2]; // 4D array
int fiveDArray[2][2][2][2][2]; // 5D array
// and so on…
(17). Which of the following operators is known as the indirection operator?
- ->
- &
- *
- None of the above
3. *
(18). Which of the following is the correct way to declare a pointer?
- int *ptr;
- int ptr
- int &ptr;
- int *ptr=0;
1. int *ptr ;
(19). A pointer can be initialized with :
- Address of the variable of the same type
- Null
- 0
- All of the above
4. All of the above
(20). Which of the following is the correct way to get value from pointer “ptr”?
- Ptr
- &ptr
- *ptr
- All of the above
3. *ptr
Advertise
(21). What is the size of a pointer?
- 4 bytes
- 8 bytes
- 16 bytes
- Vary from processor to processor
4. Vary from processor to processor
(22). Which of the following can point to any type of variable?
- Far pointer
- Null pointer
- Void pointer
- Dangling pointer
3. Void pointer
(23). Which type of memory in allocated using dynamic memory allocation?
- Stack
- Heap
- Static
- Program code
2. Heap
(24). Which of the following is/are used for dynamic memory allocation?
- malloc
- Calloc
- New
- free
(B) 1,2, and 3
(C) 2 and 3
(D) All of the above
D. All of the above
(25). Can we allocate memory for an object dynamically?
- Yes
- No
1. Yes
Advertise
(26). Which of the following operators is used to release dynamically allocated memory space?
- new
- remove
- release
- delete
4. Delete
(27). The “ delete “ is an operator in C++?
- Yes
- No
1. Yes
(28). Which is a valid way to allocate dynamic memory for an integer variable?
- int *ptr=new int(111);
- int *ptr=NULL; ptr=new int; *ptr =111;
- int *ptr; ptr=new int ; *ptr=111;
- All of the above
4. All of the above
(29). Which of the following statements is correct about class in C++?
- Class is an instance that contains data member and member functions.
- Class is fundamental and contains data members and member functions.
- Class is a blueprint for a data type that encapsulates data members and member functions.
- None of the above
3. Class is a blueprint for a data type that encapsulates data members and member functions.
(30). By default, members of a class are?
- Public
- Private
- Protected
- None of the above
2. Private
Advertise
If you have any doubts on any question please let me know in the comment section
Thank You….