Search
Close this search box.

C++ MCQs For Your Competitive or University Exam Part-2

C++ mcq

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?

  1. While loop
  2. Do….. while loop
  3. For loop
  4. 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?

  1. While loop
  2. Do…. while loop
  3. For loop 
  4. 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);

Syntax for loop:

for (initialization ; condition ; increment/decrement) {
    // code block to be executed
}

(3). Which of the following loops is normally used for a menu-driven program?

  1. Do… while loop
  2. For loop
  3. While loop 
  4. 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?

  1. While loop 
  2. For loop
  3. Do… while loop
  4. All loops require that the iterations be known

2. For loop

(5). Executions of C++ programs start from:

  1. Void function 
  2. Class
  3. Main function 
  4. 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. 1
  2. 2
  3. 3
  4. 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?

  1. Call by value 
  2. Call by reference 
  3. Call by address 
  4. 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?

  1. Within the function only
  2. Within the main function only
  3. Whole program 
  4. None of the above 

3. Whole program

(9). Which of the following statements is correct about inline function?

  1. A function is substituted at the place of call.
  2. A function that is called at compile time 
  3. A function that contains only a looping statements 
  4. None of the above 
  1. A function is substituted at the place of call.

(10). Default values for a function are defined

  1. In function declaration 
  2. In function definition 
  3. During function call
  4. None of the above 

2. In function definition 

Advertise

 

 

 

 

 

(11). Index of an array starts from: 

  1.  0
  2.  -1
  3.  2
  4.  1

1. 0

Indexing of array starts from 0.

(12). In C++ the array name denotes: 

  1. The base address of the array 
  2. The first value of the array 
  3. The last value of the array 
  4. 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?

  1. Arr[0]
  2. 0[Arr]
  3. *(Arr+0)
  4. All of the above

1. Arr[0]

(14). Can we create an array of objects in C++?

  1. Yes 
  2. No

1. Yes

Yes we can create an array of objects in c++

(15). An array occupies memory Space in:

  1. Contiguous manner 
  2. Fragmented manner 
  3. Linked list 
  4. 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++?

  1. 1D array 
  2. 2D array
  3. 3D array
  4. 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?

  1.  ->
  2.  &
  3.  *
  4.  None of the above 

3. *

(18). Which of the following is the correct way to declare a pointer?

  1. int *ptr;
  2. int ptr
  3. int &ptr;
  4. int *ptr=0;

1. int *ptr ;

(19). A pointer can be initialized with : 

  1. Address of the variable of the same type 
  2. Null
  3. 0
  4. All of the above 

4. All of the above

(20). Which of the following is the correct way to get value from pointer “ptr”?

  1. Ptr
  2. &ptr
  3. *ptr
  4. All of the above

3. *ptr

Advertise

 

 

 

 

 

(21). What is the size of a pointer?

  1. 4 bytes
  2. 8 bytes
  3. 16 bytes 
  4. Vary from processor to processor

4. Vary from processor to processor

(22). Which of the following can point to any type of variable?

  1. Far pointer 
  2. Null pointer 
  3. Void pointer
  4. Dangling pointer 

3. Void pointer

(23). Which type of memory in allocated using dynamic memory allocation?

  1. Stack 
  2. Heap
  3. Static 
  4. Program code

2. Heap

(24). Which of the following is/are used for dynamic memory allocation?

  1. malloc
  2. Calloc
  3. New
  4. free 
(A) 1 and 2
(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?

  1. Yes 
  2. No

1. Yes

Advertise

 

 

 

 

 

(26). Which of the following operators is used to release dynamically allocated memory space?

  1. new 
  2. remove 
  3. release 
  4. delete 

4. Delete

(27). The “ delete “ is an operator in C++?

  1. Yes 
  2. No

1. Yes

(28). Which is a valid way to allocate dynamic memory for an integer variable?

  1. int *ptr=new int(111);
  2. int *ptr=NULL; ptr=new int; *ptr =111;
  3. int *ptr; ptr=new int ; *ptr=111;
  4. All of the above

4. All of the above

(29). Which of the following statements is correct about class in C++?

  1. Class is an instance that contains data member and member functions.
  2. Class is fundamental and contains data members and member functions.
  3. Class is a blueprint for a data type that encapsulates data members and member functions.
  4. 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? 

  1. Public
  2. Private
  3. Protected
  4. 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….

Share:

Leave a comment

Related Posts