1. Which of the following is a valid C++ identifier?
(A) _myVar
(B) 2variable
(C) #count
(D) my-var
2. What is the output of the following code?
int x = 5; cout << ++x;
(A) 5
(B) 6
(C) 4
(D) Compilation error
3. Which operator is used to access a member function through a pointer?
‘)”> (A)
‘)”> (B) &
‘)”> (C) *
‘)”> (D) >
4. What is the size of an int on most 64-bit systems?
(A) 2 bytes
(B) 4 bytes
(C) 8 bytes
(D) Depends on compiler
5. Which of the following is NOT a valid loop in C++?
(A) for
(B) while
(C) do-while
(D) foreach
6. What is the output?
int a = 10, b = 20; cout << (a & b);
(A) 30
(B) 0
(C) 20
(D) 10
7. What will be the output?
int x = 3; int y = x++; cout << y;
(A) 3
(B) 4
(C) 2
(D) Compilation error
8. Which of the following is a correct way to declare a pointer to int?
(A) int* p;
(B) int p*;
(C) int &p;
(D) int p;
9. What will happen if you divide an int by 0?
(A) Returns 0
(B) Runtime error
(C) Undefined behavior
(D) Compile-time error
10. What is the output of this code?
char c = 'A'; cout << ++c;
(A) A
(B) B
(C) 66
(D) Compilation error
11. Which of the following is used for dynamic memory allocation?
(A) malloc()
(B) calloc()
(C) new
(D) alloc()
12. Output?
int x = 5; if(x = 0) cout << "Yes"; else cout << "No";
(A) Yes
(B) No
(C) Compilation error
(D) Garbage
13. Which keyword is used to define a constant in C++?
(A) constant
(B) const
(C) final
(D) immutable
14. What is the output?
int arr[3] = {1,2,3}; cout << arr[1];
(A) 0
(B) 1
(C) 2
(D) 3
15. Which of the following is true about references in C++?
(A) Must be initialized when declared
(B) Can be NULL
(C) Can be reassigned
(D) Use & operator to declare
16. What is the output?
int x = 7; cout << (x>>1);
(A) 3
(B) 4
(C) 7
(D) 14
17. Which of the following is correct to define a class?
(A) class MyClass {};
(B) MyClass class {};
(C) class = MyClass {};
(D) define class MyClass {};
18. Which of the following is the correct syntax for a constructor?
(A) void MyClass() {}
(B) MyClass() {}
(C) constructor MyClass() {}
(D) def MyClass() {}
19. Output?
int a=2, b=3; cout << (a^b);
(A) 5
(B) 1
(C) 6
(D) 0
20. Which of the following is correct to declare a function pointer?
(A) pointer int fp(int);
(B) int* fp(int);
(C) int fp*(int);
(D) int (*fp)(int);
21. What is the output?
int a = 10; int* p = &a; cout << *p;
(A) 0
(B) Address of a
(C) 10
(D) Compilation error
22. Which of the following is used to handle exceptions?
(A) try-catch
(B) throw-catch
(C) if-else
(D) switch-case
23. Which operator is used to allocate memory dynamically in C++?
(A) malloc
(B) new
(C) alloc
(D) calloc
24. What will be the output?
int x=10; cout << (x==10 ? "Yes" : "No");
(A) Yes
(B) No
(C) Compilation error
(D) Undefined
25. Which of the following is correct for multi-level inheritance?
(A) class C : B : A {}
(B) class C : public B : public A {}
(C) class C : public B, public A {}
(D) class C : A, B {}
26. Output?
int x=5; int y=++x + x++; cout << y;
(A) 11
(B) 12
(C) 10
(D) 9
27. Which of the following is true about virtual functions?
(A) Must be static
(B) Enables runtime polymorphism
(C) Must return void
(D) Cannot be overridden
28. Which keyword is used to prevent inheritance?
(A) final
(B) static
(C) const
(D) immutable
29. Output?
int a=5; int b=2; cout << a/b;
(A) 2
(B) 2.5
(C) 3
(D) Compilation error
30. Which of the following is true about inline functions?
(A) Compiler always inlines
(B) Cannot return value
(C) Cannot have parameters
(D) Reduces function call overhead
31. What is the output?
int a = 5; cout << a<< endl << ++a;
(A) 5 6
(B) 6 5
(C) 5 5
(D) Compilation error
32. Which of the following is a proper template syntax?
(A) template void func(T a){}
(B) template func void(T){}
(C) template func(T){}
(D) template void func(T){}
33. Output?
int x=1; x = x << 2; cout << x;
(A) 1
(B) 2
(C) 4
(D) 4
34. Which of the following is true about destructors?
(A) Called automatically when object goes out of scope
(B) Must take parameters
(C) Can be overloaded
(D) Must return int
35. Which of the following is NOT a valid access specifier?
(A) public
(B) private
(C) protected
(D) friendly
36. Output?
int x=5; int y=–x + x–; cout << y;
(A) 7
(B) 8
(C) 9
(D) 6
37. Which of the following is true about const pointer?
(A) Pointer cannot change address it points to
(B) Value pointed by pointer cannot change
(C) Both A and B
(D) None
38. Which of the following allows function overloading?
(A) Same name, same parameters
(B) Same name, different parameters
(C) Different name, same parameters
(D) Different name, different parameters
39. Which of the following is a syntax error?
(A) int a = 5;
(B) cout << "Hello";
(C) int 5b = 10;
(D) return 0;
40. Output?
int x = 10; x += 5; cout << x;
(A) 5
(B) 10
(C) 15
(D) Compilation error
41. Which of the following is a correct function declaration?
(A) int sum(int a, int b);
(B) int sum(a, b);
(C) sum int(int a, int b);
(D) int sum(int, b);
42. Output?
int a=5; cout << (a!=5 ? "Yes" : "No");
(A) Yes
(B) No
(C) Compilation error
(D) Undefined
43. Which of the following is true for pointers?
(A) Pointers store value
(B) Pointers store address
(C) Pointers store type
(D) Pointers store size
44. Which of the following is correct way to pass by reference?
(A) void func(int a) {}
(B) void func(&a) {}
(C) void func(*a) {}
(D) void func(int &a) {}
45. Output?
int x=1; int y=++x*2; cout << y;
(A) 4
(B) 2
(C) 3
(D) 1
46. Which of the following is true about static variables in function?
(A) Retains value across function calls
(B) Deleted after function exits
(C) Must be initialized every call
(D) Cannot be accessed outside function
47. Output?
int arr[3]={1,2,3}; cout << arr[3];
(A) 1
(B) 2
(C) Garbage
(D) Compilation error
48. Which of the following is true for operator overloading?
(A) Can overload all operators
(B) Cannot overload assignment operator
(C) Cannot overload sizeof operator
(D) Can overload conditional operator
49. What is the output?
int x=10; cout << x%3;
(A) 1
(B) 2
(C) 3
(D) 0
Programming C Plus Plus MCQs Homepage
- Low-level and high-level languages MCQs
- Procedural and non Procedural languages MCQs
- C++ STANDARD LIBRARY MCQs
- Array MCQs
- Arrays MCQs 2
- Pointers Solved MCQs
- Inline Function MCQs – C++
- Top 50 Programming C++ MCQs
- MCQs of introduction to programming
- Past Papers 2022 C++ MCQs
- Past Papers 2021 C++ MCQs
- Past Papers 2020 C++ MCQs
- Past Papers 2019 C++ MCQs
- Highly Recommended C++ Important MCQs with Explanation
- OOP
- OOP intro & examples MCQs
- Classes and Inheritance MCQs
- Friend Function MCQs
- Virtual Function MCQs
- Polymorphism MCQs
- Polymorphism MCQs 2

