Chapter 2: MCQs on Basic Syntax in C++ | C++ Programming

C++ Basic Syntax MCQs: Master C++ Programming Fundamentals
Enhance your knowledge of C++ programming with 30 MCQs focused on the basic syntax. Topics include the structure of a C++ program, input/output, data types, operators, and more. Perfect for beginners and intermediate learners.


MCQs

1. What is the correct structure of a basic C++ program?

  • A. Preprocessor directives, class declaration, main function
  • B. Class declaration, main function, return statement
  • C. Preprocessor directives, main function, return statement
  • D. Function definitions, main function, class declaration

2. Which of the following is the correct syntax for printing output to the console in C++?

  • A. print("Hello, World!")
  • B. echo "Hello, World!"
  • C. cout << "Hello, World!";
  • D. printf("Hello, World!");

3. In C++, which symbol is used to indicate the end of a statement?

  • A. ,
  • B. ;
  • C. .
  • D. :

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

  • A. float32
  • B. longint
  • C. double
  • D. character

5. What is the default value of an uninitialized local variable in C++?

  • A. 0
  • B. NULL
  • C. Undefined
  • D. Garbage value

6. Which keyword is used to declare a constant in C++?

  • A. constant
  • B. static
  • C. const
  • D. final

7. Which of the following is a valid declaration of an integer variable in C++?

  • A. int 1x;
  • B. int x;
  • C. int x, y;
  • D. Both B and C

8. What is the output type of cin in C++?

  • A. Integer
  • B. Character
  • C. Stream
  • D. Void

9. Which of the following is the correct way to read an integer input from the user in C++?

  • A. cin >> x;
  • B. scanf("%d", x);
  • C. read(x);
  • D. input(x);

10. Which operator is used to assign values to variables in C++?

  • A. ==
  • B. =
  • C. +=
  • D. :=

11. Which of the following operators is used for addition in C++?

  • A. +
  • B. -
  • C. *
  • D. /

12. What is the purpose of the relational operators in C++?

  • A. To perform arithmetic operations
  • B. To compare two values
  • C. To manipulate bits
  • D. To assign values to variables

13. Which of the following is a valid relational operator in C++?

  • A. <<
  • B. ==
  • C. &
  • D. !=

14. Which of the following is true about the && operator in C++?

  • A. It is used for logical AND
  • B. It is used for logical OR
  • C. It is a bitwise AND operator
  • D. It is used for string concatenation

15. Which of the following is a bitwise operator in C++?

  • A. &
  • B. &&
  • C. ==
  • D. ||

16. What does the bitwise | operator do in C++?

  • A. Performs logical OR
  • B. Performs bitwise OR
  • C. Assigns values
  • D. Performs division

17. Which of the following is an arithmetic operator in C++?

  • A. !=
  • B. +
  • C. &&
  • D. &

18. What is the purpose of the ++ operator in C++?

  • A. To increment a variable by 1
  • B. To decrement a variable by 1
  • C. To multiply a variable by 2
  • D. To divide a variable by 2

19. Which of the following operators is used to perform division in C++?

  • A. /
  • B. *
  • C. -
  • D. =

20. Which operator is used to calculate the remainder in C++?

  • A. /
  • B. *
  • C. %
  • D. &

21. What will be the output of the following C++ expression: 10 % 3?

  • A. 3
  • B. 1
  • C. 0
  • D. 10

22. Which of the following is an example of a bitwise NOT operator in C++?

  • A. &
  • B. |
  • C. ~
  • D. !

23. Which of the following operators is used for logical NOT in C++?

  • A. &
  • B. |
  • C. !
  • D. ~

24. What does the bitwise shift left operator << do in C++?

  • A. Shifts the bits of a number to the right
  • B. Shifts the bits of a number to the left
  • C. Performs logical AND
  • D. Performs logical OR

25. What is the purpose of the = operator in C++?

  • A. Assigns values
  • B. Compares values
  • C. Adds values
  • D. Multiplies values

26. What will be the output of the following C++ expression: 5 == 5?

  • A. true
  • B. false
  • C. 1
  • D. 0

27. Which operator is used to compare two values for equality in C++?

  • A. =
  • B. ==
  • C. !=
  • D. =|

28. Which of the following is true for the != operator in C++?

  • A. It checks for equality
  • B. It checks if two values are not equal
  • C. It assigns values
  • D. It adds two values

29. Which of the following is a valid assignment operator in C++?

  • A. =
  • B. ==
  • C. +=
  • D. All of the above

30. Which operator is used for compound assignment in C++?

  • A. =
  • B. +=
  • C. -=
  • D. All of the above

Answer Key

QNoAnswer
1C. Preprocessor directives, main function, return statement
2C. cout << "Hello, World!";
3B. ;
4C. double
5C. Undefined
6C. const
7D. Both B and C
8C. Stream
9A. cin >> x;
10B. =
11A. +
12B. To compare two values
13B. ==
14A. It is used for logical AND
15A. &
16B. Performs bitwise OR
17B. +
18A. To increment a variable by 1
19A. /
20C. %
21B. 1
22C. ~
23C. !
24B. Shifts the bits of a number to the left
25A. Assigns values
26A. true
27B. ==
28B. It checks if two values are not equal
29D. All of the above
30D. All of the above

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top