You are on page 1of 19

Name Ag# Course

AMINA AMEEN 2014-AG-1402 C++

Q1. What is the correct value to return to the operating system upon the successful completion of a
program?
a. 1
b. -1
C c. 0
d Programs do not return a value.
Q2. What is the only function all C++ programs must contain?
a. start()
b. system()
C c. main()
d program()
Q3 What punctuation is used to signal the beginning and end of code blocks?
A a. { }
b. -> and <-
c. BEGIN and END
d ( and )
Q4 What punctuation ends most lines of C++ code?
a. . (dot)
B b. ; (semi-colon)
c. : (colon)
d ' (single quote)
Q5 Which of the following is a correct comment?
a. */ Comments */
b. ** Comment **
C c. /* Comment */
d { Comment }
Q6 Which of the following is not a correct variable type?
a. Float
B b. Real
c. Int
d Double
Q7. Which of the following is the correct operator to compare two variables?
a. :=
b. =
c. Equal
D d ==

Q8. Which of the following is true as integer?


a. 1
b. 66
c. 8
D d All of the above

Q9. Which of the following is the boolean operator for logical-and?


a. &
B b. &&
c. |
d |&
Q10. Evaluate !(1 && !(0 || 1)).
A a. True.
b. False
c. Unevaluateable
d None
Q11 Which of the following is CPP style type-casting?
a. per = total/(float)m
B b. per = total/float(m)
c. per = (float)total/m
d None of these
Q12 Which of the following is not a casting operator in CPP?
A a. explicit_cast
b. static_cast
c. dynamic_cast
d reinterpret_cast
Q13 Logical expressions produce ____________ type results.
a. Explicit
b. Garbage
C c. Bool
d Static
Q14 Scope resolution operator is used______
a. to resolve the scope of global variables only
b. to resolve the scope of functions of the classes only
C c. to resolve scope of global variables as well as functions of the
classes
d None of these
Q15. A class can contain objects of other classes and this phenomenon is called
a. Relationship
b. Object Association
C c. Containership
d None of these
Q16. Following is the not a correct statement for preprocessor directive declaration?
a. #include<iostream.h
B b. #include<iostream.h> #define LEFT 1
c. #define LEFT 1
d #define ABS(a) (a)<0 ? –(a) : (a)

Q17. In C++ if return statements is written in a non-void function without any specified value, what
will be return value of the function?
A a. Undefined
b. 1
c. 0
d -1

Q18. In C++ how many return statements are allowed in a non-void function?
a. 1
B b. as many as you like
c. 0
d 2
Q19. In C++ if program executed successfully, following value will be returned to the calling process,
if nothing specified in return statement?
A a. 0
b. 1
c. -1
d 2
Q20. Individual characters in a string are accessed as following .
a. cout << S.at(i);
b. cout << S[i];
C c. both a) and b)
d None
Q21. Which of the following keyword is not used in exception handling
a. Try
B b. Allow
c. Catch
d Throw
Q22 Which of the following is invalid header file name?
A a. <iostring>
b. <string>
c. <iostream >
d <sstream>
Q23. The pow functions returns _____:
a. Int
B b. Double
c. String
d Float

Q24. In the following statements,


a. Hierarchical inheritance
b. Multiple inheritance
c. Multilevel inheritance
D d Both b) and c)
Q25. Which of the following are valid array declaration
a. int num(5)
B b. float avg[5]
c. double[5] marks
d counter int[5]

Q26 Which of the following are valid array declaration


A a. char str1[3] = “ab”)
b. char str1[3] = “abc”
c. char str1[2] = “ab”
d char str1[0] = “ab”

Q27 C++ supports ….


a. constant pointer)
b. pointer to a constant
c. None of above
D d Both of above
Q28 char * const ptr1 = “nice”;
A a. constant pointer)
b. pointer to a constant
c. None of above
d Both of above
Q29 In the following statement, const char * const cp = “xyz”;
a. Address assigned to pointer cp cannot be changed
b. contents it points to cannot be changed
C c. Both of above
d None of the above
Q30 In C++, symbolic constants created using
a. const
b. enum
C c. Both of above
d None of above
Q31. A friend class in C++, can access the "__________" members of the class in which it is declared
as a friend.
A a. private and protected)
b. private and public
c. public and protected
d Public
Q32. A friend function that is a "friend" of a given class is allowed access to ______data in that class.
A a. public, private, or protected )
b. public or private
c. public
d Protected

Q33 Object can be used as a function argument by..


a. Pass by value
b. Pass by reference
c. None of above
D d All of above
Q34 All member function of one class can be declared as friend function of another class, is called as :
A a. friend class
b. neighbor class
c. sister class
d inherited class
Q35 Following is the dereferencing operator
a. ?::)
b. &*
c. ->>
D d ->*

Q36 Inventor of C++ language is


a. John Dell
B b. Bjarne Stroustrup
c. Thomusn Steve
d Karl Thomus
Q37. Destructor can have following number of argument
a. 2
b. 1
C c. 0
d 5
Q38. While executing a program we first need to translate the source code into object code, it is called
as
a. debugging
b. Executing
C c. Compiling
d None
Q39. Array elements are accessed using
a. ::
b. .
c. ->
D d Index number

Q40 Following operator cannot be used for operator overloading


a. +
b. ==
C c. Size of
d None
Q41 A function that is called automatically when an object is created is called as
a. constant
B b. constructor
c. static
d Friend
Q42 The null character will take space of
a. 0 byte
b. 2 byte
C c. 1 byte
d 8 byte
Q43 This operator is used to allocate memory
A a. New
b. Delete
c. Static
d Real
Q44 A constructor that does not have any parameters is called____________ constructor.
a. Custom
b. Dynamic
c. Static
D d Default

Q45 If default constructor is not defined, then how the objects of the class will be created?
a. The compiler will generate error
b. Error will occur at run-time..
C c. Compiler provides its default constructor to build the object
d None of these
Q46 Assume class TEST. Which of the following statements is/are responsible to invoke copy
constructor?
a. TEST T2(T1)
b. TEST T4 = T1
c. T2 = T1
D d both a and b
Q47 The explicit keyword is an optional decoration for the constructors that takes
exactly_____argument.
a. No argument
b. 2
c. 3
D d 1
Q48 Run time polymorphism can be achieved with______
a. Virtual Base class .
b. Container class
C c. Virtual function
d Both a and c
Q49 ________________ is a member function that is declared within a base class and redefined by
derived class.
A a. virtual function
b. static function
c. friend function
d const member function
Q50 When a virtual function is redefined by the derived class, it is called_
a. Overloading

B b. Overriding
c. Rewriting
d All of these
Q51. Which of the followings are true about Virtual functions?
a. They must be non-static member function of the class
B b. They cannot be friends
c. Constructor Functions cannot be virtual
d All of these

Q52 While redefining a virtual function in the derived class, if its prototype is changed then
a. It will be overloaded by the compiler
b. Its virtual nature will be lost
C c. both a and b
d Compiler will generate “Prototype mismatch error
Q53 If a class contains pure virtual function, then it is termed as_____
a. Virtual class
b. Sealed class
c. Pure Local class
D d Abstract Class
Q54 Syntax for Pure Virtual Function is________
a. virtual void show()==0 .
b. void virtual show()==0
C c. virtual void show()=0
d void virtual show()=0
Q55 If abstract class is inherited by derived class, then_______________
a. Derived class should provide definition for all the pure virtual
functions
b. Derived class also become abstract if fails to implement pure
virtual functions
c. Objects of derived class can’t be created if it fails to implement
pure virtual functions
D d All of these
Q56 A virtual function that has no definition within the base class is called____________
A a. Pure virtual function.
b. Pure static function
c. Pure Const function
d Friend function
Q57 Find the wrong statement/s about Abstract Class.
a. We can’t create its objects
B b. We can’t create pointers to an abstract class
c. It contains at least one pure virtual function
d We can create references to an abstract class
Q58 Which of the following perfect set of operators can’t be overloaded in CPP ?
a. +=, ?, :: , >>
b. >>, <<, ?, *, sizeof()
C c. :: , . , .* , ?:
d :: , ->, * , new, delete
Q59. When overloading unary operators using Friend function, it requires_____ argument/s
a. 0
B b. 1
c. 2
d none
Q60 While overloading binary operators using member function, it requires ___ argument/s.
a. 0
B b. 1
c. 2
d 3
Q61. In operator overloading, the overloaded operators must have at least _____ operand of user-
defined type
a. 0
B b. 1
c. 2
d None
Q62. An operator function is created using _____________ keyword.
a. Iterator
b. Allocator
c. Constructor
D d Operator
Q63. Using friend operator function, following perfect set of operators may not be overloaded.
A a. = , ( ) , [ ] , ->
b. <<, = = , [ ] , >>
c. ?, = , ( ) , ++
d None of these
Q64. In case of binary operator overloading with member function, which of following statement
should be taken into consideration?
a. Right hand operand must be object
B b. Left hand operand must be object
c. Both the operands must be objects
d All of these should be considered
Q65. An exception is thrown using _____________ keyword in CPP
a. throws
B b. throw
c. threw
d Thrown
Q66. The code of statements which may cause abnormal termination of the program should be written
under_________ block
A a. Try
b. catch
c. Finally
d None
Q67. Exception handlers are declared with ____________ keyword
a. Try
B b. Catch
c. Throw
d Finally
Q68. In nested try block, if inner catch handler gets executed, then______________
a. Program execution stops immediately.
b. Outer catch handler will also get executed
c. Compiler will jump to the outer catch handler and then
executes remaining executable statements of main()
D d Compiler will execute remaining executable statements of
outer try block and then the main()
Q69. If inner catch handler is not able to handle the exception then__________
a. Compiler will look for outer try handler
b. Program terminates abnormally
C c. Compiler will check for appropriate catch handler of outer try
block
d None of these
Q70 Generic catch handler is represented by ______________
a. catch(..,)
b. catch(---)
C c. catch(…)
d catch( void x)
Q71. n nested try blocks, if both inner and outer catch handlers are not able to handle the exception,
then __________
a. Compiler executes only executable statements of main()
b. Compiler issues compile time errors about it
c. Program will be executed without any interrupt
D d Program will be terminated abnormally
Q72 Throwing an unhandled exception causes standard library function __________ to be invoked.
a. stop()
b. aborted()
C c. terminate()
d abandon()
Q73 How can we restrict a function to throw certain exceptions?
a. Defining multiple try and catch block inside a function
b. Defining generic function within try block
C c. Defining function with throw clause
d It is not possible in CPP to restrict a function
Q74. Attempting to throw an exception that is not supported by a function call results in calling
_____________ library function
a. indeterminate()
b. unutilized()
C c. unexpected()
d unpredicted()
Q75 Return type of uncaught_exception() is________________.
a. Int
B b. Bool
c. char *
d Double
Q76 To perform File I/O operations, we must use _____________ header file.
a. < ifstream>
b. < ofstream>
C c. < fstream>
d Any of these
Q77 To create an output stream, we must declare the stream to be of class….
A a. Ofstream
b. Ifstream
c. ifstream
d None of these
Q78 Streams that will be performing both input and output operations must be declared as class____
a. Iostream
B b. Fstream
c. Stdstream
d Stdiostream
Q79 Which of the following is not a file opening mode—
a. ios::ate
b. ios::nocreate
c. ios::noreplace
D d ios::truncate
Q80 By default, all the files are opened in ___________mode
a. Binary
B b. Text
c. Can’t say
d Both a and b
Q81 If we have object from ofstream class, then default mode of opening the file is________
a. ios::in
b. ios::out
c. ios::in|ios::trunk
D d ios::out|ios::trunk
Q82. If we have object from fstream class, then default mode of opening the file is________
a. ios::in|ios::out
b. ios::in|ios::out|ios::trunk
c. ios::in|ios::trunc
D d Default mode depends on compiler
Q83. __________is return type of is_open() function..
a. Int
B b. Bool
c. Float
d Char
Q84. Which of the following is not used to seek a file pointer?
a. ios::cur
B b. ios::end
c. . ios::set
d ios::beg
Q85. Default return type of functions in CPP is .
a. Void
b. Long
c. Char
D d Int
Q86. If a program uses Inline Function, then the function is expanded inline at -------------.
a. Compile time
B b. Run time
c. Both a and b
d None of these
Q87 Default values for a function are specified when____
a. function is defined.
B b. function is declared
c. Both a and b
d None of these
Q88 Assigning one or more function body to the same name is called_______________
a. Function Overriding
B b. Function Overloading
c. Both a and b
d None of these
Q89 If an argument to a function is declared as const, then
a. function can modify the argument
B b. Function can’t modify the argument
c. const argument to a function is not possible
d None of these
Q90 Reusability of the code can be achieved in CPP through
a. Polymorphism
b. Encapsulation
C c. Inheritance
d Both a and c
Q91 When a child class inherits traits from more than one parent class, this type of inheritance is
called _______________ inheritance.
a. Hierarchical
b. Hybrid
c. Multi level
D d Multiple

Q92 class X, class Y and class Z are derived from class BASE. This is _____________ inheritance
a. Multiple
b. Multilevel
C c. Hierarchical
d Single
Q93 The derivation of Child class from Base class is indicated by symbol.
a. ::
B b. :
c. ;
d |
Q94 During a class inheritance in CPP, if the visibility mode or mode of derivation is not provided,
then by default visibility mode is___________..
a. Public
b. Protected
CC c. Private
d friend
Q95 If the derived class is struct, then default visibility mode is_______
A a. Public
b. Protected
c. Private
d struct can’t inherit class
Q96 When a base class is privately inherited by the derived class, then_______________
a. protected members of the base class become private members
of derived class
b. public members of the base class become private members of
derived class
C c. both a and b
d Only b
Q97 What is difference between protected and private access specifiers in inheritance?
a. private member is not inheritable and not accessible in derived
class
B b. protected member is inheritable and also accessible in derived
class
c. Both are inheritable but private is accessible in the derived class
d Both are inheritable but protected is not accessible in the derived
class
Q98 In case of inheritance where both base and derived class are having constructors, when an object
of derived class is created then___________
a. constructor of derived class will be invoked first
b. constructor of base class will be invoked first
c. constructor of derived class will be executed first followed by
base class
D d constructor of base class will be executed first followed by
derived class
Q99 If base class has constructor with arguments, then it is ________________ for the derived class
to have constructor and pass the arguments to base class constructor..
a. Optional
B b. Mandatory
c. Compiler dependent
d Error
Q100 In Multipath inheritance, in order to remove duplicate set of records in child class,
we___________.
a. Write Virtual function in parent classes
b. Write virtual functions is base class
C c. Make base class as virtual base class
d All of these
Q101. What is data hiding ?
A a. It is related with hiding internal object details
b.A. It is related with showing internal object details
c. It is related with datatypes
dB. None of above
Q102 What is class in c++ ?
A a. When you define a class, you define a blueprint for a data type
b. When you define a class, you make get more functionality
c. When you define a class, you define the logic
dA. When you define a class, you make debugging.
Q103 What is object in C++ ?
a. Object is part of syntax of a class
b. Object is datatype of a class
C c. Object is an instance of a class
d Object is function of a class
Q104 What is purpose of abstract class?
a.
to provide help with database connectivity
b.
to provide data input to other classes.
c.
to provide security to other classes
D dto provide an appropriate base class from which other classes can
inherit.
Q105 What is default visibility mode for members of classes in C++ ?
A a. Private
b.A. Public
c. Protected
dB. Depends
Q106 Which is more memory efficient ?
a. Structure
B b.A. Union
c. both use same memory
d depends on a programmer
Q107 ______________are used to format the data display in CPP?
a. Iterators
b. Punctuators
C c. Manipulators
d Allocators
Q108 Which of the following manipulator is used for the representing octal equivalent of a given
decimal number ?
a. Oct
b. setbase(8)
c. tobase(8)
D d Both a and b
Q109 ___________ header file is used for manipulators.
a. < iomanipulator.h >
b. < stdiomanip.h>
c. < stdmanip.h>
D d < iomanip.h>
Q110 Predict the output:
int x = 786;
cout <<setfill(‘*’)<<setw(6)<<x;
a. 786***
b. **786
C c. ***786
d ******
Q111 Predict the output:
float x= 3.1496;
cout<<setpricision(2)<<x;
a. 3.14
b. 3.15
c. 3.00
D d None of these
Q112 During dynamic memory allocation in CPP, new operator returns__________ value if memory
allocation is unsuccessful.
a. False
B b. None
c. Zero
d None of these
Q113 Which of the following operator is used to release the dynamically allocated memory in CPP?
a. Remove
b. Free
C c. Delete
d both b and c
Q114 Which of the following is/are valid ways to allocate memory for an integer by dynamic memory
allocation in CPP?
a. int *p = new int(100);
b. int *p; p = new int; *p = 100;
c. int *p = NULL; p = new int; *p=100;
D d All of these
Q115 Which of the following is not a false statement about new operator?
a. It can’t be overloaded
b. It returns garbage value when memory allocation fails
c. It automatically computes the size of the data object
d All of these
Q116 In CPP, dynamic memory allocation is done using ______________ operator
a. calloc()
B b. malloc()
c. Allocate
d New
Q117 By default, members of the class are____________ in nature.
a. Protected
B b. Private
c. Public
d Static
Q118 C structure differs from CPP class in regards that by default all the members of the structure
are__________ in nature.
a. private
b. Protected
C c. Public
d None of these
Q119 refers to the act of representing only essential features without including the background details.
a. Data Hiding
b. Data Encapsulation
C c. Data Abstraction
d All of these
Q120 Only functions of the class can access the data of the class and they(functions) provides the
interface between data, objects and the program. This kind isolation of the data from
direct access by the program is called_______________________
a. Data Abstraction
B b. Data Hiding
c. Data Hiding
d Data Encapsulation
Q121 _________________ is the OOP feature and mechanism that binds together code and the data it
manipulates, and keep both safe from outside world.
a. Data Binding
B b. Data Encapsulation
c. Data Storing
d Data Abstraction
Q122 Object oriented programming employs_________ programming approach.
a. top-down
b. procedural
C c. Bottom up
d All of these
Q123 In CPP, cin and cout are the predefined stream__________
a. Operator
b. Functions
C c. Objects
d Data types
Q124 Classes in CPP are________
a. erived data types
B b. User defined data types
c. built-in data types
d All of these
Q125 Constant variables can be created in CPP by using________
a. Enum
b. Const
c. #define
D d All of these
Q126 When a class is defined inside any function or block, it is called_____
a. Nested class
b. Block class
C c. Local class
d It is not possible
Q127 Default value of static variable is_____
A a 0
b. 1
c. Garbage value
d Compiler dependent
Q128 Static variable in a class is initialized when
a. every object of the class is created
b. last object of the class is created
C c. first object of the class is created
d No need to initialize static variable
Q129 Static variable declared in a class are also called_________
a. instance variable
b. named constant
c. global variable
D d class variable
Q130 Which of the followings is/are pointer–to-member declarator ?
a. ->*
b. .*
C c. ::*
d Both a and b
Q131. Generic pointers can be declared with__________
a. Auto
B b. Void
c. asm
d None of these
Q132. A default catch block catches
a. All thrown objects.
b. no thrown objects
C c. any thrown object that has not been caught by an earlier catch
block
d all thrown objects that have been caught by an earlier catch block
Q133. Format flags may be combined using
A a. The bitwise OR operator
b. the logical OR operator (||)
c. the bitwise AND operator (&)
d the logical AND operator (&&)
Q134. The use of the break statement in a switch statement is:
A a. Optional
b. Compulsory
c. not allowed. It gives an error message
d To check an error
Q135. Which allows you to create a derived class that inherits properties from more than one base
class?
a. Multilevel inheritance
B b. Multiple inheritance
c. Hybrid Inheritance
d Hierarchical Inheritance
Q136. Which feature in OOP allows reusing code?
a. Polymorphism
B b. Inheritance
c. Encapsulation
d Data hiding
Q137. A function that changes the state of the cout object is called a(n) _____
a. . member
b. adjuster
C c. manipulator
d Operator
Q138. What does C++ append to the end of a string literal constant?
a. a space
b. a number sign (#)
c. an asterisk (*)
D d a null character
Q139. An array element is accessed using
a. a first-in-first-out approach
b. the dot operator
c. a member name
D d an index number
Q140. To hide a data member from the program, you must declare the data member in the _____
section of the class
a. Concealed
b. Confidential
c. Hidden
D d Private
Q141. External documentation includes
A a. a printout of the program's code
b. flowcharts
c. IPO charts
d pseudo code
Q142. The function whose prototype is void getData(Item *thing); receives
A a. a pointer to a structure
b. a reference to a structure
c. a copy of a structure
d Nothing
Q143. Null character needs a space of
a. zero bytes
B b. one byte
c. three bytes
d four bytes
Q144 The number of structures than can be declared in a single statement is
a. 1
b. 2
c. 3
D d Unlimited
Q145. Which of the following formulas can be used to generate random integers between 1 and 10?
A a. 1 + rand() % (10 - 1 + 1)
b. 1 + (10 - 1 + 1) % rand()
c. 10 + rand() % (10 - 1 + 1)
d 10 + rand() % (10 + 1)
Q146 Format flags may be combined using the _____
A a. bitwise OR operator (|)
b. logical OR operator (||)
c. bitwise AND operator (&)
d logical AND operator (&&)
Q147 Which of the following will store the number 320000 as a Float number?
A a. counPop = (float) 3.2e5;
b. counPop = (float) 3.2e6;
c. counPop = (float) .32e5;
d counPop = (float) .32e7;
Q148. The arguments that determine the state of the cout object are called
a. classes
b. Manipulators
C c. format flags or state flags
d state controllers
Q149. Which of the following statements declares a variable that can contain a decimal number?
a. dec payRate;
b. dec hourlyPay
c. float payRate
D d float hourlyPay;
Q150. The statement int num[2][3]={ {1,2}, {3,4}, {5, 6} };
a. assigns a value 2 to num[1][2] .
b. assigns a value 4 to num[1][2]
C c. gives an error message
d assigns a value 3 to num[1][2]
Answers:

Q1. C Q.51 D Q.101 A


Q2. C Q52 C Q102 A
Q3. A Q53 D Q103 C
Q4. B Q54 C Q104 D
Q5. C Q55 D Q105 A
Q6. B Q56 A Q106 B
Q7. D Q57 B Q107 C
Q8. D Q58 C Q108 D
Q9. B Q59 B Q109 D
Q10. A Q60 B Q110 C
Q11. B Q.61 B Q111 D
Q12. A Q62 D Q112 B
Q13. C Q63 A Q113 C
Q14. C Q64 B Q114 D
Q15. C Q65 B Q115 C
Q16. B Q66 A Q116 D
Q17. A Q67 B Q117 B
Q18. B Q68 D Q118 C
Q19. A Q69 C Q119 C
Q20. C Q70 C Q120 B
Q21. B Q.71 D Q121 B
Q22. A Q72 C Q122 C
Q23. B Q73 C Q123 C
Q24. D Q74 C Q124 B
Q25. B Q75 B Q125 D
Q26. A Q76 C Q126 C
Q27. D Q77 A Q127 A
Q28. A Q78 B Q128 C
Q29. C Q79 D Q129 D
Q30. C Q80 B Q130 C
Q31. A Q81 D Q131 B
Q32. A Q82 D Q132 C
Q33. D Q83 B Q133 A
Q34. A Q84 B Q134 A
Q35. D Q85 D Q135 B
Q36. B Q86 B Q136 B
Q37. C Q87 B Q137 C
Q38. C Q88 B Q138 D
Q39. D Q89 B Q139 D
Q40. C Q90 C Q140 D
Q41. B Q91 D Q141 A
Q42. C Q92 C Q142 A
Q43. A Q93 B Q143 B
Q44. D Q94 C Q144 D
Q45. C Q95 A Q145 A
Q46. D Q96 C Q146 A
Q47. D Q97 B Q147 A
Q48. C Q98 D Q148 C
Q49. A Q99 B Q149 D
Q50 B Q100 C Q150 C

You might also like