0% found this document useful (0 votes)
96 views

C++ Test

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

C++ Test

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

AISECT EDUCATION

C++ Test

NAME - MM – 25

CLASS - OBT –

CHOOSE THE CORRECT OPTION:-

1. What is the correct syntax to declare a variable in C++?

a) var name; b) name var c) int name; d) variable name;

2. Which of the following is the correct way to initialize an integer variable named "x" with the value
10?

a) int x = 10; b) int x; c) x = int(10); d) int(10) = x;

3. What is the output of the following code?

#include <iostream>

int main() {

int x = 5;

int y = x++;

std::cout << y << std::endl;

return 0;

a) 4 b) 5 c) 6 d) Compiler error

4. Which of the following is NOT a valid C++ data type?

a) double b) bool c) string d) char

5. What is the correct way to define a function named "add" that takes two integer parameters and
returns their sum?

a) add(int x, int y) { return x + y; } b) void add(int x, int y) { return x + y; }

c) int add(int x, int y) { return x + y; } d) int add(int x, y) { return x + y; }

6. What is the purpose of the "break" statement in a switch statement?

a) It terminates the program execution. b) It skips the current iteration of the loop.

c) It transfers control to the next case in the switch statement.

d) It transfers control to the default case in the switch statement.

7. What is the output of the following code?

#include <iostream>

int main() {

int arr[] = {1, 2, 3, 4, 5};

int *ptr = arr;


std::cout << *(ptr + 2) << std::endl;

return 0;

a) 1 b) 2 c) 3 d) 4

8. What is the correct way to dynamically allocate memory for an integer variable in C++?

a) int *x = new int(); b) int x = new int(); c) int *x = malloc(sizeof(int)); d) int x =


malloc(sizeof(int));

9. What is the scope of a local variable in C++?

a) The variable can be accessed from any part of the program. b) The variable can be accessed only
within the function where it is declared.

c) The variable can be accessed within the file where it is declared. d) The variable can be accessed
only within the class where it is declared.

10. What is the purpose of the "cin" object in C++?

a) To read input from the user. b) To display output on the console.

c) To perform mathematical calculations. d) To handle exceptions in the program.

11. Which of the following is the correct syntax to add the header file in the C++ program?

A) #include<userdefined> B) #include "userdefined.h"

C)<include> "userdefined.h" D) Both A and B

12). Which of the following is not a kind of inheritance?

A.Distributed B.Multiple

C.Multi-level D.Hierarchal

13) Which type of approach is used by the C++ language?

1)Right to left 2)Left to right

3)Top to bottom 4)Bottom-up

14) Among the following, which shows the Multiple inheritances?

1)X,Y->Z 2)X->Y->Z

3)X->Y;X->Z 4)None of the above

15) Which of the following options correctly explains the concept of Polymorphism?

a. int func(float); float func(int, int, char); b.int func(int); int func(int);

c.int func(int, int); float func1(float, float); d. None of the above


16)Which of the following is a correct identifier in C++?

a) VAR_1234 b) $var_name
c) 7VARNAME d) 7var_name

17) Which of the following correctly declares an array in C++?


a) array{10}; b) array array[10];
c) int array; d) int array[10];

18) Which of the following is used to terminate the function declaration in C++?
a) ; b) ] c) ) d) :

19) For inserting a new line in C++ program, which one of the following statements can be used?

a)\n b)\r c) \a d)None of the above

20) Which of the following refers to characteristics of an array?

a)An array is a set of similar data items b)An array is a set of distinct data items

c)An array can hold different types of datatypes d)None of the above

21) If we stored five elements or data items in an array, what will be the index address or the index
number of the array's last data item?

a)3 b)5 c)4 d)88

22) Which of the following statements is correct about the friend function in C++ programming
language?

a)A friend function is able to access private members of a class

b)A friend function can access the private members of a class

c)A friend function is able to access the public members of a class

d)All of the above

23) More than one user-defined function can have the same name and perform different operations.
This feature of c++ is known as ___.
a) Function overloading b) operator overloading
c) overloading d) None of these

24) ___ member function invoked automatically whenever the objects are destroyed or expired
a) destructor ~ b) constructor c) polymorphism d)dynamic binding

25)

You might also like