100 MCQ Questions of C++ (Variables, Data Type & Operator) || Programming || Computer Technology || Edu Verse BY Pratik || Code With Pratik

C++ MCQs

C++ Multiple Choice Questions

1. What is the result of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 7;
    int b = 2;
    cout << a % b << endl;
    return 0;
}
        
Answer: B) 1

2. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    float a = 3.5;
    int b = 2;
    cout << a / b << endl;
    return 0;
}
        
Answer: A) 1.75

3. Which of the following statements about data types is true?

Answer: A) `char` can store integers

4. What will the following code output?

#include <iostream>
using namespace std;

int main() {
    bool flag = true;
    cout << !flag << endl;
    return 0;
}
        
Answer: A) 0

5. What is the result of the following expression?

#include <iostream>
using namespace std;

int main() {
    int x = 5;
    x += 10;
    cout << x << endl;
    return 0;
}
        
Answer: A) 15

6. Which operator is used to perform the bitwise OR operation in C++?

Answer: A) |

7. What is the output of this code?

#include <iostream>
using namespace std;

int main() {
    int x = 7;
    cout << ++x << endl;
    return 0;
}
        
Answer: A) 8

8. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    char ch = 'B';
    cout << ch + 1 << endl;
    return 0;
}
        
Answer: A) C

9. Which operator is used for logical AND in C++?

Answer: B) &&

10. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    x *= 3;
    cout << x << endl;
    return 0;
}
        
Answer: A) 30

11. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    cout << x-- << endl;
    return 0;
}
        
Answer: A) 10

12. What is the result of this expression?

#include <iostream>
using namespace std;

int main() {
    float x = 7.0;
    int y = 3;
    cout << x / y << endl;
    return 0;
}
        
Answer: A) 2.3333

13. Which operator is used for bitwise XOR operation in C++?

Answer: A) ^

14. What will the following code output?

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 4;
    cout << a + b * 2 << endl;
    return 0;
}
        
Answer: A) 13

15. What will be the output of this code?

#include <iostream>
using namespace std;

int main() {
    float a = 2.5;
    int b = 4;
    cout << a * b << endl;
    return 0;
}
        
Answer: A) 10.0

16. Which of the following is a correct way to declare a `short` integer variable in C++?

Answer: A) short int x;

17. What will be the output of this code?

#include <iostream>
using namespace std;

int main() {
    int x = 3;
    int y = 5;
    cout << (x + y) * (x - y) << endl;
    return 0;
}
        
Answer: A) -16

18. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    char ch = 'Z';
    cout << ++ch << endl;
    return 0;
}
        
Answer: A) [

19. Which of the following is used for modulo division in C++?

Answer: A) %

20. What will the following code print?

#include <iostream>
using namespace std;

int main() {
    int x = 5;
    int y = 4;
    cout << x % y << endl;
    return 0;
}
        
Answer: A) 1

21. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 8;
    int b = 3;
    cout << a / b << endl;
    return 0;
}
    
Answer: A) 2

22. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 4;
    int y = 5;
    cout << (x + y) * 2 << endl;
    return 0;
}
    
Answer: A) 18

23. What is the result of the following operation: 10 % 3 in C++?

Answer: B) 1

24. Which of the following statements is true about the `char` data type in C++?

Answer: A) It is used to represent a single character.

25. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    int y = x++;
    cout << y << endl;
    cout << x << endl;
    return 0;
}
    
Answer: A) 10 11

26. What is the result of the following operation: 5 * 2 >> 1 in C++?

Answer: B) 10

27. Which of the following is a correct statement about the `++` operator in C++?

Answer: A) It increments the value of a variable by 1.

28. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 4;
    int y = 3;
    cout << x * y << endl;
    return 0;
}
    
Answer: B) 12

29. Which of the following is the correct syntax to declare a variable `x` of type `float`?

Answer: D) All of the above

30. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 7;
    int y = 3;
    cout << (x % y) + 1 << endl;
    return 0;
}
    

31. What is the size of `int` on a typical 32-bit system?

Answer: B) 4 bytes

32. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    float a = 1.2f;
    double b = 1.2;
    cout << (a == b) << endl;
    return 0;
}
    
Answer: A) 0

33. Which of the following is a valid way to declare a variable in C++?

Answer: B) float number;

34. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    cout << ++x << endl;
    return 0;
}
    
Answer: B) 11

35. Which operator is used to perform integer division in C++?

Answer: A) /

36. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 8;
    cout << x / 3 << endl;
    return 0;
}
    
Answer: B) 2

37. Which of the following is the correct syntax to declare a constant variable in C++?

Answer: D) Both A and C

38. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 7;
    int b = 3;
    cout << a % b << endl;
    return 0;
}
    
Answer: A) 1

39. What is the result of `5 + 3 * 2` in C++?

Answer: B) 11

40. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 15;
    cout << a / 4 << endl;
    return 0;
}
    
Answer: A) 3

41. What is the size of `char` in C++?

Answer: A) 1 byte

42. Which of the following data types can store floating-point numbers in C++?

Answer: C) float

43. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 2;
    int b = 3;
    cout << a++ * ++b << endl;
    return 0;
}
    
Answer: A) 6

44. Which operator is used to compare two values in C++?

Answer: B) ==

45. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    bool flag = true;
    cout << !flag << endl;
    return 0;
}
    
Answer: B) false

46. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 9;
    cout << x % 4 << endl;
    return 0;
}
    
Answer: A) 1

47. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 5;
    int y = x++;
    cout << y << endl;
    return 0;
}
    
Answer: A) 5

48. Which data type is used to store a single character in C++?

Answer: C) char

49. What is the result of `10 / 3` in C++ when `10` and `3` are integers?

Answer: A) 3

50. What is the correct syntax for declaring a `double` variable in C++?

Answer: A) double num;

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

Answer: C) real

52. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 10;
    cout << a + b * 2 << endl;
    return 0;
}
    
Answer: C) 25

53. What is the correct way to declare a variable `score` of type `int` and initialize it to 100?

Answer: A) int score = 100;

54. Which of the following is used to perform logical AND operation in C++?

Answer: A) &&

55. What is the result of `7 % 3` in C++?

Answer: A) 1

56. What is the correct syntax for a `for` loop in C++?

Answer: A) for (int i = 0; i < 10; i++) { /* code */ }

57. Which of the following data types is used for boolean values in C++?

Answer: A) bool

58. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 2;
    int y = 4;
    cout << x * y / 2 << endl;
    return 0;
}
    
Answer: A) 4

59. What is the correct way to declare a variable `price` of type `float`?

Answer: D) Both A and B

60. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 10;
    cout << a-- << endl;
    return 0;
}
    
Answer: A) 10

61. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 8;
    int b = 3;
    cout << a / b << endl;
    return 0;
}
    
Answer: A) 2

62. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    double a = 5.5;
    int b = 2;
    cout << a / b << endl;
    return 0;
}
    
Answer: A) 2.75

63. What is the size of a `long long` variable on most systems?

Answer: B) 8 bytes

64. Which of the following is the correct syntax for using a `switch` statement in C++?

Answer: A) switch (expression) { case value: /* code */ break; }

65. Which of the following data types has the largest size in C++?

Answer: D) long long

66. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 3;
    int b = 2;
    cout << a / b << endl;
    cout << a % b << endl;
    return 0;
}
    
Answer: A) 1 1

67. Which of the following is a valid floating-point literal in C++?

Answer: D) Both A and C

68. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 1;
    int b = 2;
    cout << a + b * 2 << endl;
    return 0;
}
    
Answer: A) 5

69. Which of the following is the correct way to declare an array of 5 integers in C++?

Answer: A) int arr[5];

70. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 3;
    int b = 4;
    cout << ++a + b++ << endl;
    return 0;
}
    
Answer: A) 8

71. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 10;
    cout << (a < b ? a : b) << endl;
    return 0;
}
    
Answer: B) 5

72. Which of the following statements is true about `unsigned int`?

Answer: A) It can store only positive numbers.

73. What is the size of a `short` variable on most systems?

Answer: A) 2 bytes

74. Which operator is used to access members of a structure in C++?

Answer: A) .

75. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 5;
    x *= 3;
    cout << x << endl;
    return 0;
}
    
Answer: A) 15

76. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 10;
    cout << (a > b) << endl;
    return 0;
}
    
Answer: A) 0

77. Which of the following is a correct statement about `const` variables in C++?

Answer: A) Their value cannot be changed once initialized.

78. What is the default value of a `bool` variable in C++ if not explicitly initialized?

Answer: A) false

79. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 7;
    cout << (x % 3 == 1) << endl;
    return 0;
}
    
Answer: A) 1

80. Which operator is used for equality comparison in C++?

Answer: A) ==

81. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 10;
    cout << a++ << endl;
    cout << a << endl;
    return 0;
}
    
Answer: A) 10 11

82. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 4;
    int y = 5;
    cout << x > y ? x : y << endl;
    return 0;
}
    
Answer: B) 5

83. Which of the following is a valid integer literal in C++?

Answer: D) All of the above

84. What is the result of the following operation: 7 & 3 in C++?

Answer: A) 3

85. Which of the following operators has the highest precedence in C++?

Answer: A) * (multiplication)

86. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    cout << x-- << endl;
    cout << x << endl;
    return 0;
}
    
Answer: A) 10 9

87. What is the result of the operation 5 ^ 3 in C++?

Answer: A) 6

88. What is the result of the operation 5 << 1 in C++?

Answer: A) 10

89. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    bool flag = true;
    cout << !flag << endl;
    return 0;
}
    
Answer: A) 0

90. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 5;
    x += 10;
    cout << x << endl;
    return 0;
}
    
Answer: A) 15

91. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 5;
    cout << (a == b) << endl;
    return 0;
}
    
Answer: A) 1

92. Which of the following is a correct statement about the `sizeof` operator in C++?

Answer: A) It returns the size of a variable in bytes.

93. What is the size of an `int` variable on most systems?

Answer: B) 4 bytes

94. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    int y = 20;
    cout << (x > y ? x : y) << endl;
    return 0;
}
    
Answer: B) 20

95. Which of the following is a correct statement about `float` in C++?

Answer: A) It is used to represent floating-point numbers.

96. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 7;
    x /= 2;
    cout << x << endl;
    return 0;
}
    
Answer: A) 3

97. What will be the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int a = 5;
    int b = 2;
    cout << (a % b) << endl;
    return 0;
}
    
Answer: A) 1

98. What is the result of the operation 3 * 2 > 5 in C++?

Answer: A) true

99. Which of the following operators has the lowest precedence in C++?

Answer: D) & (bitwise AND)

100. What is the output of the following code?

#include <iostream>
using namespace std;

int main() {
    int x = 10;
    x += 5;
    x -= 3;
    cout << x << endl;
    return 0;
}
    
Answer: B) 13

Thank You for Visiting!

We are deeply grateful for your time and attention. Your engagement with our content means a lot to us, and we hope that the information provided has been valuable and insightful for your C++ journey.

We strive to create resources that empower and inspire. If you found our content useful, please consider sharing it with others who might benefit from it. Your support helps us continue to provide quality content and make a difference in the programming community.

If you have any feedback, suggestions, or questions, we’d love to hear from you. Feel free to reach out through our contact page or leave a comment. Together, let's continue to learn and grow in the fascinating world of C++ programming!

Thank you once again for your visit. Keep coding and stay curious!

Post a Comment

Previous Post Next Post