C++ Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Chandigarh Group of Colleges

Department of Training
Objective Questions Module
1. An entity representing some characteristics and behaviour is-
a) object
b) class
c) struct
d) none of the above

2. Which of the following is not the feature of OOPs?


a) Data Encapsulation
b) Inheritance
c) Polymorphism
d) None of the above
3. The wrapping up of data and functions into a single unit is
a) Data Abstraction
b) Data Encapsulation
c) Both (a) & (b)
d) None of the above

4. Which of the following feature supports reusability and extensibility of classes?


a) Inheritance
b) Overloading
c) Polymorphism
d) None of the above

5. Inheritance is ………..in nature.


a) Intransitive
b) Transitive
c) Both (a) & (b)
d) None of the above

6. ………… is the ability for a message or data to be processed in more than one form
a) Class
b) Abstraction
c) Polymorphism
d) None of the above

7. The smallest individual unit in a program is ………


a) Keyword
b) Identifier
c) Token
d) None of the above

8. Which of the following features of procedure oriented programming is false


a) Large programs are divided into small or units called functions.
b) Employs bottom-up approach in program design.
c) Most of the functions share global data.
d) None of the above.

9. Which of the following features of object oriented programming is false?


a) Data is hidden and is not available to external functions.
b) New data & functions can be added easily.
c) Objects may communicate with each other through functions.
d) Emphasis is on the procedure rather than data.

10. The following is the C++ style comment


a) //
b) /*..*/
c) –
d) None of the above

11. Which of the following statements is false?


a) Every C++ program must have a main().
b) In C++, white spaces and carriage returns are ignored by the compiler.
c) C++ statements terminate with semicolon.
d) Main() terminates with semicolon.

12. An identifier in C++


a) Must begin with a letter only
b) Is not differentiated by cases
c) Contains all characters as significant
d) None of the above

13. 010 is an example of


a) decimal constant
b) octal constant
c) hexadecimal constant
d) None of the above

14. A sequence of characters surrounded by double quotes is


a) Character literal
b) String literal
c) Both (a) & (b)
d) None of the above

15. The following data type specifies an empty set of values


a) Void
b) Int
c) Char
d) None of the above

16. ………. Provides a value for a variable


a) declaration statement
b) assignment statement
c) definition statement
d) None of the above

17. A collection of variables referred under one name


a) Structure
b) Class
c) Union
d) None of the above

18. A memory location shared by two or more different variables


a) Structure
b) Class
c) Union
d) None of the above

19. The constants defined using enum keyword are


a) Symbols
b) Enumerators
c) Keywords
d) None of the above

20. The operator ?: is


a) Logical operator
b) Relational operator
c) Conditional operator
d) Arithmetic operator

21. A loop containing other loop is


a) Nested
b) Inner
c) Outer
d) None of the above

22. The following statement forces the next iteration of the loop to take place
a) break
b) continue
c) goto
d) None of the above

23. gets() function is available in


a) stdio.h
b) string.h
c) ctype.h
d) stdlib.h

24. In C++, the statements are enclosed within


a) parenthesis
b) square brackets
c) curly brackets
d) None of the above

25. The following tells the compiler where the program begins
a) Function prototype
b) Forward declaration of class
c) main()
d) None of the above

26. << operator is


a) stream insertion operator
b) stream extraction operator
c) left shift operator
d) None of the above

27. “H” is an example of


a) character literal
b) string literal
c) variable
d) None of the above

28. Which of the following statements regarding comments is false?


a) /*..*/
b) Comment beginning with // extends to the end of the line
c) Comments may be nested
d) Comments are used to describe a program

29. C++ is
a) Procedural programming language
b) Structural programming language
c) Object oriented programming language
d) None of the above

30. y=x=2; in C++ will result in


a) compilation error
b) runtime error
c) assignment of value to x then to y
d) None of the above

31. In C++, ………. is the statement terminator


a) semicolon
b) colon
c) new line
d) None of the above

32. Modules operator (%) has higher precedence than


a) Divide (/) operator
b) Multiply (*) operator
c) Negation (unary minus)
d) Bitwise left shift operator

33. The result of the following statement is


int y = 7;
intans = ++y;
cout<<”ans=”<<ans;
cout<<”y”<<y;

a) ans=7, y=7
b) ans=8,y=7
c) ans=8,y=8;
d) none of the above

34. Consider the following if construct


If(x=0)
cout<<”Inside loop!”;
cout<<”Outside loop”;
The result of the above code segment is.

a) inside loop
b) outside loop
c) both (a) & (b)
d) none of the above

35. The result of 2 & 3 is


a) 2
b) 3
c) 5
d) none of the above

36. Which of the following statements regarding enumerators is false?


a) Enumeration is an alternative method for naming integer constants/
b) An enumerator value can’t be changed in a program
c) An integer value may be assigned to an enumerated variable
d) An enum defined within a structure is local to the structure

37. Which of the following statements is false?


a) typedef defines new data types
b) Using typedef does not replace the standard C++ data type name with the new name
c) The new name defined by typedef, can be used as a type for another typedef
d) None of the above

38. Data members and member functions are enclosed within


a) class
b) structure
c) union
d) None of the above

39. Inline functions are


a) Declared in the class defined outside the class
b) Defined outside the class using keyword intime
c) Defined inside the class using keyword inline
d) None of the above

40. The default class access scope is


a) Private
b) Public
c) Protected
d) None of the above

41. The default scope for a structure is


a) Private
b) Public
c) Protected
d) None of the above

42. The private data members of a class are accessible


a) Directly to objects of that class
b) Only to the member functions
c) To any function defined outside a class
d) None of the above

43. The objects can directly access


a) Public members
b) Private members
c) Both (a) & (b)
d) None of the above

44. The following is a valid statement in C++


a) int x=(int)2.50;
b) int x=int(2.50);
c) Both (a) & (b)
d) None of the above

45. Which of the following operator can be overloaded


a) Member access operator ( .& .*)
b) Conditional operator (?:)
c) Scope resolution operator (::)
d) None of the above

46. Using same function name to perform different tasks is


a) Function polymorphism
b) Runtime polymorphism
c) Function prototype
d) None of the above

47. Default argument is


a) Specified in function definition
b) Specified in function declaration
c) Specified from left to right
d) None of the above

48. What is wrong with the following statement?


floats_interest (float principal, int rate=0.25, int time);

a) variables must not be specified in function prototype


b) arguments may only be defaulted from right to left
c) the default value must be specified when making a function call
d) none of the above

49. Which of the following statements regarding function overloading is not true.
a) If is used to handle different data types at one place
b) When making a function call, if no exact match is found, promotion is the only criteria to find a match.
c) The default arguments can not be used instead of overloading
d) Unrelated functions should not be overloaded

50. The private members of a class implement the OOP concept of


a) Data abstraction
b) Data hiding
c) Message passing
d) None of the above

51. When a member function of a class call another member function, it is


a) Nesting of classes
b) Nesting of functions
c) Nesting of objects
d) None of the above

52. A function defined inside a class is called


a) A class function
b) A friend function
c) A member function
d) None of the above

53. Information is made shareable through


a) inheritance
b) data encapsulation
c) data abstraction
d) none of the above

54. Functions can returns


a) arrays
b) reference
c) object
d) all of the above

55. The memory for date members is allocated


a) When a class is defined
b) When an object is initialized
c) When an object is created
d) None of the above

56. The memory for member functions is allocated


a) When a class is defined
b) When a object is created
c) When an object is initialized
d) None of the above

57. The dot operator relates


a) A class member and a class object
b) A class object and a class
c) A class and a member of that class
d) A class object and member of that class

58. A class having another class definition is


a) Nested class
b) Subordinate class
c) Enclosing class
d) None of the above

59. A class whose member functions are friends of other class is


a) Friend class
b) Abstract class
c) Virtual class
d) None of the above

60. The data members of a class are initialized


a) in class definition
b) by a non-member function
c) through constructor function when a class object is created
d) none of the above

61. A constructor function is


a) A friend function to a class
b) A member function with the same name as its class
c) A non-member function
d) None of the above

62. An enumerated type is composed of


a) Integer values with user defined name
b) Variables of different data types
c) Constant numeric values
d) None of the above

63. In C++, the arguments by default are passed by


a) call be reference
b) call be value
c) both (a) & (b)
d) none of the above

64. ?is an example of


a) unary operator
b) binary operator
c) ternary operator
d) none of the above

65. new operator is used


a) to define a new variable
b) to create a new data type
c) to allocate memory dynamically
d) none of the above

66. A constructor function is generally defined


a) In the public section of a class
b) In the private section of a class
c) In the protected section of a class
d) None of the above

67. A class having no public constructors is


a) A private class
b) A public class
c) An abstract class
d) None of the above

68. If a constructor function is defined in private section of a class, then


a) The object cannot be created
b) Only member functions and friends may declare objects of the class
c) Both (a) & (b)
d) None of the above

69. A constructor with no argument is


a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) None of the above

70. If default arguments are provided to a constructor function, then it becomes


a) Default constructor
b) Copy instructor
c) Parameterized constructor
d) None of the above

71. The class of which the objects are not instantiated is


a) Abstract class
b) Virtual class
c) Static class
d) None of the above

72. && denotes


a) logical OR
b) logical AND
c) Bitwise AND
d) None of the above

73. The parameterized constructor


a) Needs initial values as arguments during creation of an object
b) Can be invoked explicitly only
c) Can be invoked implicitly only
d) None of the above

74. Explicit call to a constructor means


a) Providing the constructor name explicitly to invoke it
b) Not providing the construction name at all
c) Is the shorthand method
d) None of the above

75. Classes in C++ are


a) Fundamental data type
b) Primitive data type
c) Desired data type
d) None of the above

76. A copy constructor is called


a) When an object is defined and initialized with another object
b) When an object is passed by value
c) When a function returns an object
d) All of the above

77. Which of the following regarding constructor function is false?


a) Constructor functions don’t have return type, not even void
b) Constructors can’t be inherited
c) We can refer to their addresses
d) Constructors cannot be virtual

78. If new operator is used, then the constructor function is


a) Parameterized constructor
b) Copy constructor
c) Dynamic constructor
d) Default constructor

79. Which of the following statements regarding constructor is false?


a) A constructor may be defined static
b) Constructor can have default arguments
c) Member functions may be invoked from within a constructor
d) None of the above

80. The antonym of constructor is


a) Creator
b) Destructor
c) Destroyer
d) None of the above

81. Variable …………. of void type


a) May be declared
b) Cannot be declared
c) Can be initialized
d) None of the above

82. A destruction function


a) Takes no argument and has no return type not even void
b) Has name similar to that of class, preceded by tilde(~) symbol
c) Is used to destruct an object, constructed through constructor function
d) All of the above

83. Which of the following statements regarding destructor function is false?


a) Destructors do not accept any arguments, nor do they return any values
b) Destructors can be inherited
c) Member functions may be called from within a destructor
d) Destructor functions are called automatically when an object is destroyed

84. Function overloading


a) Involves several function definitions under one name, but different argument types
b) Implements polymorphism
c) Reduces the number of comparison in a program, hence increases the execution speed of a program
d) All of the above

85. The signature of function is


a) The number & type of arguments
b) The return type of a function
c) The class definition
d) None of the above

86. Overloading of constructor function


a) is similar to function overloading
b) different from an overloaded function as it can’t return a value
c) not permitted in C++
d) none of the above

87. The binding of a function call at runtime is


a) Static binding
b) Early binding
c) Late binding
d) Runtime binding

88. The process of giving special meaning to an operator is


a) Operator overloading
b) Operator mechanism
c) Operator definition
d) None of the above

89. The function used to define the task assigned to an operator is


a) Virtual function
b) Operator function
c) Static function
d) None of the above

90. The following operators can not be overloaded


a) Unary operator
b) Binary operator
c) Ternary operator
d) None of the above

91. Which of the following statements regarding operator overloading is not true?
a) New operators cannot be created while overloading
b) The semantics of an operator cannot be changed while overloading
c) Subscript operator([]) can be overloaded
d) None of the above

92. Which of the following statements can be overloaded?


a) Size of operator
b) Scope resolution operator (::)
c) Class member access operator (->)
d) Pointer to member operator

93. Operator functions


a) Can return a value
b) Cannot return a value
c) May return values of limited data types
d) None of the above

94. While overloading, a unary operator


a) Takes no arguments
b) Takes one argument
c) Takes two arguments
d) None of the above
95. While overloading, a binary operator
a) takes no argument
b) takes one argument
c) takes two arguments
d) none of the above

96. Which of the following operators cannot be overloaded?


a) increment and decrement operator
b) function call operator, ()
c) subscript operator, []
d) none of the above

97. When an arithmetic assignment operator is overloaded, the result


a) goes in the object to the left of the operator
b) goes in the object to the right of the operator
c) goes in the object of which the operator is a member
d) none of the above

98. The function that overloads as operator, precedes with the keyword
a) function
b) operator
c) virtual
d) static

99. The symbol **


a) can be overloaded
b) cannot be overloaded as it is not a C++ operator
c) cannot be overloaded, as on overloading its meaning shall be changed
d) none of the above

100. The stream insertion and extraction operators should be overloaded as


a) friend functions
b) member function
c) non member functions
d) none of the above

Answer Keys :

(1) A (2) D (3) B (4) A

(5) B (6) C (7) C (8) B

(9) D (10) A (11) D (12) C

(13) B (14) B (15) A (16) B

(17) A (18) C (19) B (20) C

(21) A (22) B (23) A (24) C

(25) C (26) A (27) B (28) C

(29) C (30) C (31) A (32) C

(33) C (34) B (35) A (36) C

(37) A (38) A (39) B (40) A

(41) B (42) B (43) A (44) C

(45) D (46) A (47) B (48) B

(49) C (50) B (51) B (52) C


(53) A (54) D (55) B (56) A

(57) D (58) C (59) A (60) C

(61) B (62) A (63) B (64) C

(65) C (66) A (67) A (68) C

(69) A (70) A (71) A (72) B

(73) A (74) A (75) C (76) D

(77) C (78) C (79) A (80) B

(81) B (82) D (83) B (84) D

(85) A (86) B (87) C (88) A

(89) B (90) C (91) D (92) C

(93) A (94) A (95) B (96) D

(97) A (98) B (99) B (100) A

You might also like