You are on page 1of 10

RAJALAKSHMI ENGINEERING COLLEGE

Thandalam, Chennai – 602 105


Department of Computer Science and Engineering
CS17302 - OBJECT ORIENTED PROGRAMMING
Unit-I-Class Test

Reg. No. : Name :

Year : Branch: Section:

I. Choose the best answer:

1. #include <iostream> is called _____.


a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned

Answer: a

2. The #include directive:


a) Tells the preprocessor to grab the text of a file and place it
directly into the current file
b) Statements are not typically placed at the top of a program
c) All of the mentioned
d) None of the mentioned

Answer: a

Explanation: The #include directive tells the preprocessor to grab


the text of a file and place it directly into the current file and are
statements are typically placed at the top of a program.

3. If the file name is enclosed in double quotation marks:


a) The preprocessor treats it as a user-defined file
b) The preprocessor treats it as a system-defined file
c) The preprocessor treats it as a user-defined file & system-defined
file
d) None of the mentioned

Answer: a

4. If the file name is enclosed in angle brackets:


a) The preprocessor treats it as a user-defined file
b) The preprocessor treats it as a system-defined file
c) The preprocessor treats it as a user-defined file & system-defined
file
d) None of the mentioned

Answer: b
5. How many types of comments are there in C++?
a) 1
b) 2
c) 3
d) 4

Answer: b

Explanation: There are two types of comments. They are double slash
and slash started.

6. What type of comments does C++ support?


a) single line
b) multiline
c) single line and multi-line
d) none of the mentioned

Answer: c

7. What is a comment in C++?


a) comments are parts of the source code disregarded by the compiler
b) comments are executed by the compiler to find the meaning of the
comment
c) comments are executable
d) none of the mentioned

Answer: a

Explanation: Comments are used to add meaning to the program.

8. Comments in C++ starts with _____ symbol.


a) //
b) \\
c) **
d) None of the above

Answer: a

9. What is used to write multi line comment in C++?


a) /* …. */
b) /$ …. $/
c) //
d) none of the mentioned

Answer: a

Explanation: The /* is used to write the multi line comment.

2 B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai


10. Pick the odd one out:
a) array type
b) character type
c) boolean type
d) integer type

Answer: a

Explanation: Array type is not the basic type and it is constructed


using the basic type.

11. Which data type is used to represent the absence of parameters?


a) int
b) short
c) void
d) float

Answer: c

Explanation: void will not return anything.

12. Which type is best suited to represent the logical values?


a) integer
b) boolean
c) character
d) all of the mentioned

Answer: b

Explanation: Logical values can be either true or false, so the


boolean type is suited for it.

13. Is bool a fundamental data type in C++?


a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false, true}
d) No, it is expanded from macros

Answer: a

Explanation: C++ has bool as a fundamental data type.

14. Which of the following is not one of the sizes of the floating point
types?
a) short float
b) float
c) long double
d) double

Answer: a

B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai 3


Explanation: Floating point types occur in only three sizes-float,
long double and double.

15. The size of an object or a type can be determined using which


operator?
a) malloc
b) sizeof
c) malloc
d) calloc

Answer: b

Explanation: The sizeof operator gives the size of the object or


type.

16. It is guaranteed that a _____ has at least 8 bits and a _____ has at
least 16 bits.
a) int, float
b) char, int
c) bool, char
d) char, short

Answer: d

17. Which of the following will not return a value?


a) null
b) void
c) empty
d) free

Answer: b

18. Which operator is having the highest precedence?


a) postfix
b) unary
c) shift
d) equality

Answer: a

Explanation: The operator which is having highest precedence is


postfix and lowest is equality.

19. The precedence of arithmetic operators is (from highest to lowest):


a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /

Answer: a

4 B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai


20. Where does the execution of the program starts?
a) user-defined function
b) main function
c) void function
d) none of the mentioned

Answer: b

Explanation: Normally the execution of the program in C++ starts from


main only.

21. How many minimum numbers of functions need to be presented in C++?


a) 0
b) 1
c) 2
d) 3

Answer: b

Explanation: The main function is the mandatory part, it is needed


for the execution of the program to start.

22. All keywords in C++ are in


a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned

Answer: a

23. Which of the following is not a valid C++ variable name?


a) int number;
b) float rate;
c) int variable_count;
d) int $main;

Answer: d

Explanation: Since only underscore and no other special character is


allowed in a variable name, it results in an error.

24. Which of the following is true for variable names in C++?


a) They can contain alphanumeric characters as well as special
characters
b) It is not an error to declare a variable to be one of the
keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

Answer: c

B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai 5


Explanation: According to the syntax for C variable name, it cannot
start with a digit.

25. Which is valid C++ expression?


a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;

Answer: b
Explanation: Space, comma and $ cannot be used in a variable name.

26. Which of the following is not an arithmetic operation?


a) a *= 10;
b) a /= 10;
c) a != 10;
d) a %= 10;

Answer: c

27. Operation “a = a * b + a” can also be written as:


a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
c) a = (b + 1)* a;
d) All of the mentioned

Answer: d

28. Which of the following data type will throw an error on modulus
operation (%)?
a) char
b) short
c) int
d) float

Answer: d

29. Which among the following is NOT a logical or relational operator?


a) !=
b) ==
c) ||
d) =
Answer: d

30. Which of the following are unary operators?


a) sizeof
b) –
c) ++
d) all of the mentioned

Answer: d

6 B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai


31. Associativity of an operator are:
a) Right to Left
b) Left to Right
c) Random fashion
d) Both Right to Left and Left to Right

Answer: d

32. Which of the following method are accepted for assignment?


a) 5 = a = b = c = d;
b) a = b = c = d = 5;
c) a = b = 5 = c = d;
d) None of the mentioned

Answer: b

33. Which of the following operators has the lowest precedence?


a) !=
b) &&
c) ?:
d) ,

Answer: d

34. Which operator is used for input stream?


a) >
b) >>
c) <
d) <<

Answer: b

Explanation: The operator of extraction is >> and it is used on the


standard input stream.

35. The if...else statement can be replaced by which operator?


a) Bitwise operator
b) Conditional operator
c) Multiplicative operator
d) None of the mentioned

Answer: b

Explanation: In the conditional operator, it will predicate the


output using the given condition.

36. The switch statement is also called as?


a) choosing structure
b) selective structure
c) certain structure
d) none of the mentioned

B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai 7


Answer: b

Explanation: The switch statement is used to choose the certain code


to execute, So it is also called as selective structure.

37. What is this operator called ?:?


a) conditional
b) relational
c) casting operator
d) none of the mentioned

Answer: a

Explanation: In this operator, if the condition is true means, it


will return the first operator, otherwise second operator.

38. Which of the following is a ternary operator?


a) &&
b) >>=
c) ?:
d) ->

Answer: c

39. Which operator works only with integer variables?


a) increment
b) decrement
c) both increment & decrement
d) none of the mentioned

Answer: c

40. How many types are there in increment/decrement operator?


a) 1
b) 2
c) 3
d) 4

Answer: b

Explanation: There are two types of increment/decrement. They are


postfix and prefix.

41. Pick out the correct statement.


a) Increment operator ++ adds 1 to its operand
b) Increment operator ++ adds 2 to its operand
c) Decrement operator ++ subtracts 1 to its operand
d) None of the mentioned

Answer: a

8 B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai


42. Example of iteration in C++.
a) for
b) while
c) do-while
d) all of the mentioned

Answer: d

43. Which looping process is best used when the number of iterations is
known?
a) for
b) while
c) do-while
d) all looping processes require that the iterations be known

Answer: a

44. The following code ‘for(;;)’ represents an infinite loop. It can be


terminated by _____.
a) break
b) exit(0)
c) abort()
d) all of the mentioned

Answer: a

45. Which loop is most suitable to first perform the operation and then
test the condition?
a) for loop
b) while loop
c) do-while loop
d) none of the mentioned

Answer: c

46. The keyword ‘break’ cannot be simply used within:


a) do-while
b) if-else
c) for
d) while

Answer: b

47. Which keyword is used to come out of a loop only for that iteration?
a) break
b) continue
c) return
d) none of the mentioned

Answer: b

B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai 9


48. The insertion operator is another name for _____.
a) input operator
b) output operator
c) extraction operator
d) None of the above

Answer: b

49. The extraction operator is another name for _____.


a) input operator
b) output operator
c) extraction operator
d) None of the above

Answer: a

50. When will the cin can start processing of input?


a) After pressing return key
b) BY pressing blank space
c) After pressing return key & BY pressing blank space
d) None of the mentioned

Answer: a

10 B.BHUVANESWARAN | AP (SG) | CSE | Rajalakshmi Engineering College | Chennai

You might also like