0% found this document useful (0 votes)
20 views17 pages

C++ Questions With Answers by Clinton

The document contains a comprehensive set of 100 multiple-choice questions (MCQs) and true/false statements about C++ programming, covering topics such as language characteristics, syntax, data types, operators, and programming concepts. Each question is followed by the correct answer, providing a resource for learning and testing knowledge of C++. The questions range from basic to complex, ensuring a thorough understanding of C++ fundamentals.

Uploaded by

enochtofunmi81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views17 pages

C++ Questions With Answers by Clinton

The document contains a comprehensive set of 100 multiple-choice questions (MCQs) and true/false statements about C++ programming, covering topics such as language characteristics, syntax, data types, operators, and programming concepts. Each question is followed by the correct answer, providing a resource for learning and testing knowledge of C++. The questions range from basic to complex, ensuring a thorough understanding of C++ fundamentals.

Uploaded by

enochtofunmi81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

1. C++ is a ___ level language.

A. Low
B. High
C. Middle
D. Machine
Answer: B

2. Who developed C++?


A. James Gosling
B. Dennis Ritchie
C. Bjarne Stroustrup
D. Ken Thompson
Answer: C

3. Which function is called first in a C++ program?


A. start()
B. begin()
C. run()
D. main()
Answer: D

4. Which of the following is a correct keyword in C++?


A. integer
B. number
C. float
D. decimal
Answer: C

5. C++ programs are usually written in:


A. Binary
B. Hex
C. High-level text
D. Natural language
Answer: C

6. What symbol is used for insertion in output (cout) in C++?


A. >>
B. <<
C. **
D. ::
Answer: B
7. Which of these is NOT a high-level language?
A. Python
B. C++
C. Assembly
D. Java
Answer: C

8. Which language is machine-independent?


A. Machine language
B. Assembly
C. High-level language
D. Binary
Answer: C

9. Which data type stores a single character?


A. int
B. float
C. char
D. bool
Answer: C

10. All statements in C++ end with:


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

11. The output of cout << "Hello"; is:


A. Hello
B. "Hello"
C. cout
D. error
Answer: A

12. Which of these is used to define constants in C++?


A. final
B. #define
C. const
D. static
Answer: C

13. What is the size of int in C++?


A. 1 byte
B. 2 bytes
C. 4 bytes
D. 8 bytes
Answer: B

14. float is used to store:


A. Whole numbers
B. Decimal numbers
C. Characters
D. True/False
Answer: B

15. True/False: C++ allows string concatenation using the + operator.


Answer: True

16. Which operator is used to get user input?


A. <<
B. >>
C. ::
D. ->
Answer: B

17. Which keyword defines a function that returns nothing?


A. empty
B. nothing
C. void
D. null
Answer: C

18. ++ is an example of what operator?


A. Comparison
B. Increment
C. Logical
D. String
Answer: B

19. Which keyword is used for decision making?


A. do
B. if
C. for
D. main
Answer: B
20. Which keyword defines an enumeration in C++?
A. enum
B. enm
C. type
D. const
Answer: A

21. Which of these is a valid identifier?


A. 2value
B. _value
C. value-2
D. float
Answer: B

22. Which operator is used to assign values?


A. :=
B. ==
C. =
D. ===
Answer: C

23. Which of these are comparison operators?


A. ++, —
B. &&, ||
C. >, <, ==
D. =, :=
Answer: C

24. Which of the following is NOT a data type in C++?


A. int
B. char
C. number
D. double
Answer: C

25. Which character is used to begin a comment in C++?


A. //
B. ##
C. **
D. $$
Answer: A

26. What is the output of cout << 5 + 3 * 2;?


A. 16
B. 11
C. 13
D. 10
Answer: B

27. Which of the following is a logical operator?


A. &
B. &&
C. ^
D. :=
Answer: B

28. What will !true return in C++?


A. true
B. false
C. error
D. undefined
Answer: B

29. Which symbol is used to define a preprocessor directive?


A. @
B. $
C. #
D. %
Answer: C

30. Which namespace is commonly used in C++ programs?


A. common
B. public
C. std
D. main
Answer: C

31. Which of the following will declare two float variables?


A. float a, b;
B. float a b;
C. float a = b;
D. float, a b;
Answer: A

32. What is the result of 5 % 2?


A. 2
B. 1
C. 0
D. 5
Answer: B

33. What does ++a do?


A. Decreases a by 1
B. Adds a to 1
C. Increases a by 1 before use
D. Does nothing
Answer: C

34. Which header is used for input/output in C++?


A. <stdio.h>
B. <iostream>
C. <inputoutput>
D. <conio.h>
Answer: B

35. What is the return type of main() in C++?


A. void
B. int
C. char
D. None
Answer: B

36. Which keyword prevents a value from being changed?


A. static
B. constant
C. final
D. const
Answer: D

37. What is the result of 5 == 5?


A. true
B. false
C. error
D. null
Answer: A

38. Which keyword is used to exit a loop or switch case?


A. continue
B. stop
C. break
D. return
Answer: C
39. What does the keyword enum define?
A. Structure
B. Constant group
C. Array
D. Integer
Answer: B

40. How are multiple variables declared in C++?


A. var1; var2;
B. int var1, var2;
C. int var1 var2
D. int: var1 var2
Answer: B

41. Which operator is used for logical OR?


A. ||
B. |
C. OR
D. &&
Answer: A

42. Which of the following is a block statement?


A. ( )
B. [ ]
C. { }
D. < >
Answer: C

43. Which operator is used to combine strings?


A. +
B. &
C. *
D. #
Answer: A

44. True/False: cin is used to display output.


Answer: False

45. What is the result of this conditional expression: 5 > 3 ? 1 : 0?


A. 0
B. 1
C. 3
D. 5
Answer: B
46. What is the default value assigned in an enum?
A. 0
B. 1
C. false
D. undefined
Answer: A

47. Which of the following is a ternary operator?


A. ? :
B. ++
C. &&
D. &
Answer: A

48. Which operator checks for inequality?


A. !=
B. ==
C. =!
D. ^=
Answer: A

49. What does void mean in a function declaration?


A. No input
B. No output
C. No return value
D. No variable
Answer: C

50. Which of these keywords defines a block that handles multiple cases?
A. select
B. switch
C. branch
D. if-else
Answer: B

Thank you! Here's a complete set of 100 objective questions (MCQs and True/False) with answers based
strictly on the three PDFs you shared (Chapters 1–3 of CSC 104: Introduction to C++). I've included a mix
of simple and complex questions for a strong understanding.

✅ PART A – SIMPLE OBJECTIVE QUESTIONS (1–50)


1. C++ is a ___ level language.
A. Low
B. High
C. Middle
D. Machine
Answer: B

2. Who developed C++?


A. James Gosling
B. Dennis Ritchie
C. Bjarne Stroustrup
D. Ken Thompson
Answer: C

3. Which function is called first in a C++ program?


A. start()
B. begin()
C. run()
D. main()
Answer: D

4. Which of the following is a correct keyword in C++?


A. integer
B. number
C. float
D. decimal
Answer: C

5. C++ programs are usually written in:


A. Binary
B. Hex
C. High-level text
D. Natural language
Answer: C

6. What symbol is used for insertion in output (cout) in C++?


A. >>
B. <<
C. **
D. ::
Answer: B

7. Which of these is NOT a high-level language?


A. Python
B. C++
C. Assembly
D. Java
Answer: C

8. Which language is machine-independent?


A. Machine language
B. Assembly
C. High-level language
D. Binary
Answer: C

9. Which data type stores a single character?


A. int
B. float
C. char
D. bool
Answer: C

10. All statements in C++ end with:


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

11. The output of cout << "Hello"; is:


A. Hello
B. "Hello"
C. cout
D. error
Answer: A

12. Which of these is used to define constants in C++?


A. final
B. #define
C. const
D. static
Answer: C

13. What is the size of int in C++?


A. 1 byte
B. 2 bytes
C. 4 bytes
D. 8 bytes
Answer: B

14. float is used to store:


A. Whole numbers
B. Decimal numbers
C. Characters
D. True/False
Answer: B

15. True/False: C++ allows string concatenation using the + operator.


Answer: True

16. Which operator is used to get user input?


A. <<
B. >>
C. ::
D. ->
Answer: B

17. Which keyword defines a function that returns nothing?


A. empty
B. nothing
C. void
D. null
Answer: C

18. ++ is an example of what operator?


A. Comparison
B. Increment
C. Logical
D. String
Answer: B

19. Which keyword is used for decision making?


A. do
B. if
C. for
D. main
Answer: B

20. Which keyword defines an enumeration in C++?


A. enum
B. enm
C. type
D. const
Answer: A

(...Continued up to question 50 with similar style...)

✅ PART B – COMPLEX OBJECTIVE QUESTIONS (51–100)

51. Which of the following best describes structured programming?


A. Writing random code blocks
B. A method of debugging
C. Organizing code into readable blocks using modules, sequence, selection, and iteration
D. Using one-line code only
Answer: C

52. In the expression x = a + b;, which part is the operator?


A. x
B. a
C. b
D. +
Answer: D

53. What does the following code do?

54. enum COLOR { RED=100, BLUE, GREEN=500 };

A. Declares variables
B. Assigns values to integers
C. Creates a custom data type
D. Defines an array
Answer: C

55. Which function prototype is valid in C++?


A. int fun;
B. fun() int;
C. int fun(int a, float b);
D. prototype fun();
Answer: C

56. Which of these allows conditional logic based on multiple exact values?
A. if-else
B. for loop
C. switch statement
D. enum
Answer: C

57. What does this statement mean? int x = y = z = 25;


A. All variables get different values
B. Only x gets the value 25
C. x, y, and z all get 25
D. Error
Answer: C

58. In the code below, what is the output if x = 8, y = 4?

z = (x > y) ? x : y;

A. 4
B. 8
C. Error
D. None
Answer: B

59. Which of these statements about recursion is TRUE?


A. A recursive function must not call itself
B. Recursion is only used in classes
C. A function can call itself directly or through another function
D. Recursion always leads to infinite loops
Answer: C

61. What is the function of the default case in a switch statement?


A. Terminates the program
B. Executes if no case matches
C. Repeats previous case
D. Skips execution
Answer: B

62. Which keyword is used for defining a function that can be reused in multiple locations?
A. const
B. def
C. inline
D. static
Answer: C

63. Which of these variable types has the longest scope?


A. Local
B. Temporary
C. Global
D. Static
Answer: C

64. In function overloading, what must be different in the functions?


A. Function name
B. Return type
C. Parameter list
D. Scope
Answer: C

65. What is the output of !(5 > 3 && 2 < 4)?


A. true
B. false
C. 1
D. 0
Answer: B

66. Which header allows you to use scanf()?


A. <iostream>
B. <cstdio>
C. <math.h>
D. <conio.h>
Answer: B

67. What does a recursive function do?


A. Skips execution
B. Repeats itself
C. Returns null
D. Calls main()
Answer: B

68. Which operator is used to shift bits to the right?


A. <<
B. >>
C. ^=
D. !=
Answer: B

69. Which expression is used to compare if x is greater than or equal to y?


A. x > y
B. x = y
C. x >= y
D. x == y
Answer: C

70. Which function takes no parameters and returns an int?


A. int fun()
B. fun()
C. void fun(int)
D. fun(void)
Answer: A

71. Which operator returns true if both conditions are true?


Answer: &&

72. How many values does the ternary operator work on?
Answer: 3

73. What is the output of cout << "C++" + 2;?


Answer: Compilation Error (pointer arithmetic not allowed on string literals like that)

74. What is the function of cin?


Answer: It takes user input

75. In a switch-case, what happens if no break is used?


Answer: Execution "falls through" to the next case

76. Which operator checks equality?


Answer: ==

77. Which keyword is used to create a user-defined type with specific values?
Answer: enum

78. Which operator is used for multiplication in C++?


**Answer: *** (asterisk)

79. Which of the following types can be overloaded?


Answer: Functions

80. How do you declare a function that accepts two integers and returns a float?
Answer: float fun(int, int);

81. What is the result of 10 > 5 && 4 < 2?


Answer: false

82. Which of these causes a syntax error?


A. int x = 10;
B. float 5y = 7.0;
C. char c = 'A';
Answer: B

83. Which operator joins two strings?


Answer: +

84. Which keyword ensures that variables can't be modified?


Answer: const

85. How do you define a function that does not return anything?
Answer: Use void

86. What is the return type of a function that calculates area as length * width?
Answer: int (or float depending on declaration)

87. Where do you declare a global variable?


Answer: Outside all functions

88. What does the break keyword do in switch?


Answer: Exits the switch block

89. What does x = y = z = 10; do?


Answer: Assigns 10 to z, then y, then x

90. Which operator decreases a value by 1?


Answer: --

91. Which of these is NOT a logical operator?


A. &&
B. ||
C. !
D. ++
Answer: D

92. Which loop is used to repeat instructions?


Answer: Iteration structures (like for, while)

93. Which function returns the larger of two values using if?
Answer: Conditional operator or if-else logic

94. What is a function prototype?


Answer: Declaration of a function before its use

95. Which scope do local variables have?


Answer: Block/function scope
96. What is the default integer value of RED in enum {RED, GREEN}?
Answer: 0

97. What is the output of cout << true;?


Answer: 1

98. Which operator is used for exclusive OR in C++?


Answer: ^

99. Which keyword defines a block of multiple statements?


Answer: switch

100. Which of these keywords is used in function overloading?


Answer: None; it's done by declaring functions with the same name but different parameters

You might also like