C / C++ Programming Questions

1. What is the output of the following code?

A. 1

B. 2

C. 4

D. 8

      C. 4

2. Which of the following is not a valid C++ data type?

A. int

B. float

C. real

D. double

      C. real

3. What is the output of the following code?

A. 10

B. 11

C. Address of a

D. Compilation error

      B. 11

4. Which keyword is used to define a class in C++?

A. class

B. struct

C. object

D. new

      A. class

5. What is the output of the following code?

A. 1

B. 2

C. 3

D. 4

      C. 3

6. Which type of inheritance is not supported in C++?

A. Single

B. Multiple

C. Multilevel

D. Cyclic

      D. Cyclic

7. What is the output of the following code?

A. 10

B. 20

C. 0

D. Compilation error

      A. 10

8. What is the output of the following code?

A. Constructor called

B. No output

C. Compilation error

D. Runtime error

      A. Constructor called

9. What is the output of the following code?

A. 4

B. 5

C. 6

D. Compilation error

      B. 5

10. Which keyword is used to achieve runtime polymorphism in C++?

A. virtual

B. static

C. const

D. inline

      A. virtual

11. Which function is used to open a file in C?

A. fopen

B. open

C. read

D. write

      A. fopen

12. What is the output of the following code?

A. 5

B. 6

C. 6.0

D. Compilation error

      C. 6.0

13. What is the output of the following code?

A. 5

B. 10

C. Address of a

D. Compilation error

      B. 10

14. Which keyword is used to handle exceptions in C++?

A. try

B. catch

C. throw

D. All of the above

      D. All of the above

15. What is the output of the following code?

A. 1

B. 2

C. 3

D. Compilation error

      C. 3

16. Which operator cannot be overloaded in C++?

A. +

B. –

C. ::

D. *

      C. ::

17. Which function is used to allocate memory dynamically in C?

A. malloc

B. calloc

C. realloc

D. All of the above

      D. All of the above

18. Which container is used to store unique elements in C++ STL?

A. vector

B. list

C. set

D. map

      C. set

19.What is the output of the following code?

A. 25

B. 11

C. 10

D. Compilation error

      B. 11

20. What is the output of the following code?

A. 5

B. 0

C. Compilation error

D. Runtime error

      A. 5

Scroll to Top