Professional Documents
Culture Documents
OOP MCQ
OOP MCQ
A. Static function
B. Friend function
C. Const function
D. Virtual function
ANSWER: B
A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor
ANSWER: B
A. operator
B. function
C. object
D. macro
ANSWER: C
Which of the following concepts meANSWER wrapping up of data and functions together?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
ANSWER: B
A. >>
B. <<
C. +
D. =
ANSWER: B
A. iostream
B. istream
C. ostream
D. ifstream
ANSWER: C
Which of the following is correct about the statements given below? I. All operators can be
overloaded in C++. II. We can change the basic meaning of an operator in C++.
A. Only I is true.
C. Only II is true.
ANSWER: B
A. []
B. ->
C. ?:
D. *
ANSWER: C
Which of the following header file includes definition of cin and cout?
A. istream.h
B. ostream.h
C. iomanip.h
D. iostream.h
ANSWER: D
A. overload
B. operator
C. friend
D. override
ANSWER: B
A. public
B. private
C. protected
D. friend
ANSWER: D
A. protected
B. public
C. private
D. friend
ANSWER: C
A. A static member function can access only static data members of a class.
B. A static data member is shared among all the object of the class.
C. A static data member can be accessed directly using class name in main().
D. Both A and B.
ANSWER: D
B. Break
C. Protected
D. Asm
ANSWER: C
Which of the following can access private data members or member functions of a class?
ANSWER: C
Which of the following type of data member can be shared by all instances of its class?
A. Public
B. Inherited
C. Static
D. Friend
ANSWER: C
C. Two or more functions with the same name but different number of parameters or type.
ANSWER: C
A. 1
B. 2
C. 3
D. 4
ANSWER: D
Which function allows you to set minimum width for the next input?
A. setfill
B. setw
C. setwidth
ANSWER: B
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
ANSWER: C
A. ^
B. v
C. <<
D. >>
ANSWER: C
A. ^
B. v
C. <<
D. >>
ANSWER: D
which of the following is input statement in C++?
A. cin
B. input
C. get
D. none of above
ANSWER: A
A. print
B. write
C. cout
D. cin
ANSWER: C
Regarding the use of new line character (/n) and endl manipulator with cout statement
ANSWER: B
A. +
B. ::
C. -
D. ~
ANSWER: B
A static function
ANSWER: C
We can output text to an object of class ostreamusing the insertion operator<< because
ANSWER: D
A white space is :
A. blank space
B. new line
C. tab
ANSWER: D
ANSWER: C
A. conio.h
B. fstream.h
C. stdio.h
D. iostream.h
ANSWER: D
Statement cin >> ch ; will start executing when we press _______ key.
A. any
B. any character
C. only character
D. escape
E. enter
ANSWER: E
You have a variable myNum that has the value 5. You want to print your variable to screen. How
would you do it?
ANSWER: D
ANSWER: A
A. \c
B. \m
C. \f
D. \g
ANSWER: C
Which of the following is not an escape sequence?
A. \x
B. \y
C. \t
D. \\
ANSWER: B
A. operator
B. function
C. object
D. macro
ANSWER: C
How to insert values in array of objects using new for an array int a[] at position n
D. None of these
ANSWER: A
Suppose we have a class Weather and array of objects called w of size 10 i.e.,Weather w[10]. How to
delete memory of certain object at position say 'i'?
A. renew w[i]
B. ~Weather(i)
C. delete w[i];
D. All of these
ANSWER: C
ANSWER: B
int *ptr[5];
D. none of above
ANSWER: A
If the class Shape is an abstract class, what type of variable may be declared of the type Shape?
C. Objects of the class shape may be declared only if object of a class that is derived from Shape is
also declared
ANSWER: D
What will be the output of the following code: inline double cube(double a) { return(a*a*a); } The
above inline function can be invoked by the statements like d=cube(2.5+1.5);
A. 64
B. 27
C. can predict
ANSWER: A
B. It is visible only within the class , but its lifetime is the entire program
C. Only one copy of that member is created for the entire class and is shared by all the object of that
class.
ANSWER: D
What happens when a class with parametrized constructor and having no default constructor is used
in the program and we create an object that needs a zero argument constructor
B. Preprocessing error
C. Runtime error
D. Runtime exeption
ANSWER: A
II. They are invoked automatically when the objects are created
III. They do not have any return type, not even void
A. I,II,III,V
B. II,III,IV,V
C. I,III,IV,V
D. I,II,III,IV,V
ANSWER: D
A. Data abstraction
B. Data hiding
C. Message passing
ANSWER: B
A destructor
ANSWER: D
C. both a & b
ANSWER: A
A. Intransitive
B. Transitive
C. Both A & B
ANSWER: B
b. The . operator
c. The [ ] operator
b. Binary operators can have one argument and unary operators cannot have any.
d. Binary operators can have two arguments and unary operators can have one.
Ans. b
Ans. D
a0 Preprocessor directives
c0 Standard operators
d0 None of these
Ans. C
I If you do not want to make use of operator overloading, you can achieve that effect using user
defined function.
a0 Only I is true
b0 Only II is true
b. While overloading using the friend function the binary operator requires one argument.
d. None of these.
Ans. c
a. ()
b. []
c. ->
d. *
Ans. d
Ans. B
d. All of these
Ans. C
The inheritance is described as a ________relationship
a. has a
b. is a
c. association
d. None of these
Ans. b
Irrespective of the type of derivation_____members of base class are never accessible in derived
class
a. Public
b. Private
c. Protected
d. None of these
Ans. b
Which of the following allows you to create a derived class that inherits properties from more than
one base class?
a. Multilevel inheritance
b. Multiple inheritance
c. Single inheritance
d. Hybrid inheritance
Ans. b
The principle by which the knowledge of general category can be applied to more specific objects is
called_______.
a. Polymorphism
b. Overriding
c. Inheritance
d. None of these
Ans. a
Using multiple inheritance________.
d. None of these
Ans. a
If class C is a derived class of class B and class B is a derived class of A. If we istantiate class B object
then the first constructor called belongs to class ____.
a. A
b. B
c. Can be A or B
Ans. A
Suppose class Derived is derived from a class Base privately. The object of class Derived is located in
main() can access _______.
Ans. d
What does the derived class does not inherit from the base class_____.
b. Operator=() member
c. Friends
d. All of these
Ans. D
If class A is a friend class of class B, if class B is friend class of class C then ______.
d0 None of these
Ans.c
a. Friend
b. Virtual
c. Abstract
d. None of these
Ans. a
d. All of these
Ans. d
When a class uses dynamic memory allocation, the destructor of the class must _____.
Ans. c
Which of the following statements correctly allocates space to store 15 real numbers?
Ans. a
a.zero
b.null
c.0
Ans. a
b.All the allocated memory must be deallocated before the object goes out of scope
and the destructor is called.
d.It must include the dynamic allocation in all the constructors, and it must then
deallocate all of the allocated memory in the destructor.
Ans. d
a.late binding
b.early binding
c.dynamic allocation
Ans. a
The new operator returns to_________.
Ans. c
a.stack
b.array
c.pointer
d.none of these
Ans. c
Following is used to allocate and deallocate the memory for the object.
a.stack
b.garbage collection
c.heap
d.none of these
Ans. c
a. 100 MB
b. 1000 MB
c. 1024 MB
d. Unlimited
Ans. d
a. default constructor
b. dynamic constructor
c. parameterized constructor
d. none of these
Ans. b
a) Static binding
b) Early binding
c) Late binding
d) Runtime binding
A. abstract
B. Virtual
C. Dynamic
D. Typeid
Ans: B
d. none of these.
Ans. C
A pure virtual function is a function that_______
b. returns nothing
c. takes no arguments
d. none of these
Ans a
Ans. D
a) Size of vector
b) Type of vector
c) Number of elements
ans. c
#include<iostream>
Class TEST
Public:
Int x,y;
TEST() {};
TEST(int,int);
};
TEST::TEST(int a , int b)
X = a;
Y = b;
TEST temp;
Temp.x = x + ob.x;
Temp.y = y + ob.y;
Return(temp);
Int main()
TEST a (10,20);
TEST b (1,2);
TEST c;
C=a + b;
Return o;
a0 10 20
b0 1 2
c0 11 22
d0 30 3
Ans. c
What will be the output of the following code ?
# include <iostream>
Class A
Public:
A(int a)
Cout<<” “<<a;
};
Class B: public A
Public:
Cout<<” “<<b;
};
Class C:public B
Public:
Cout<<” “c;
};
Int main()
C c(10,20,30);
Return 0;
}
a0 Garbage garbage 30
b0 30 20 10
c0 10 20 30
d0 Syntax error
Ans. C
# include <iostream>
Class Base
Protected:
Int a;
Public:
Base(int x)
a= x;
~Base()
{ }
};
Int b;
Public:
b= x;
}
~Derived()
{ }
Void display()
Cout<<a<<” “<<b<<endl;
};
Int main()
Derived obj(100,200);
Obj.display();
Return 0;
a0 100 200
b0 200 100
c0 Syntax error
d0 100 100
Ans. b
# include <iostream>
Class Base
Public:
Base()
};
Class derived: public Base
Public:
Derived()
};
Int main()
Base b;
Derived d;
Return 0;
In Base class
In Derived class
In Base class
In Derived class
In Base class
In Base class
In Derived class
In Base class
Creating Derived class object….
In Base class
In Derived class
Ans. d
# include <iostream>
Class Base
Public:
Base(void)
Base (int i)
};
Base()
};
};
Public:
D2(void)
~D2(void)
};
Int main(void)
D1 a;
D2 b;
D2 c(100);
Return 0;
a0 Base()
Base()
D2()
Base(100)
D2(100)
~D2()
~Base()
~D2()
~Base()
~Base()
b0 Syntax error
c0 Runtime error
d0 None of These
Ans. b
Class Test:public A, pubic B is an example of _______.
a. Single inheritance
b. Multiple inheritance
c. Repeated inheritance
d. None of these
Ans. b
Which of the following interface determines how your program will be used by other program?
a. Public
b. Private
C. Protected
d. None of these
Ans. a
# include <iostream>
Class A
Protected:
Int x,y;
Public:
X = a; y = b;
};
Class B
Public:
Void display (int i);
};
Void B::display(int i)
Public:
Int add()
Return(x + y);
};
Public:
Int add()
Return(x + y +10);
};
Int main()
C obj1;
D obj2;
Obj1.setvalues(10,20);
Obj2.setvalues(10,20);
Obj1.display(obj1.add());
Obj2.display(obj2.add());
Return 0;
}
a0 10 20
b0 30 40
c0 20 40
d0 None of these
Ans. b
What are the design requirements for building a container from the sratch?
c) Iterator requirements.
Ans. D
b) Code pattern
c) Glue pattern
Ans. a
ANSWER: C
___ and __are used for dynamic memory allocation in C++.
ANSWER: D
A. static
B. dynamic
C. const
D. smart
ANSWER: B
A. Pointer
B. Array
C. Stack
ANSWER: A
A. Parameterized constructor
B. Copy constructor
C. Dynamic constructor
D. Default constructor
ANSWER: C
B. Class for which two or more than two objects will be created
C. Class for which copy constructor is defined
ANSWER: D
A. 100 MB
B. 1000 MB
C. 1024 MB
D. Unlimited
ANSWER: D
A. free
B. delete
C. clear
D. remove
ANSWER: B
D. none of these
ANSWER: B
When a class uses dynamic memory allocation, the destructor of the class must _____.
ANSWER: C
Which of the following statements correctly allocates space to store 15 real numbers?
ANSWER: A
A. zero
B. null
C. 0
ANSWER: A
B. All the allocated memory must be deallocated before the object goes out of scope and the
destructor is called.
D. It must include the dynamic allocation in all the constructors, and it must then deallocate all of
the allocated memory in the destructor.
ANSWER: D
A. new
B. malloc
C. create
D. value
ANSWER: A
B. malloc
C. sizeof
D. realloc
ANSWER: C
A. Copy constructor
B. Default constructor
C. Static constructor
D. Dynamic constructor
ANSWER: D
Which area of process address space is used for dynamic memory allocation?
A. Stack
B. Heap
C. Garbage Collection
D. Anywhere
ANSWER: B
Which of the following is correct to allocate a memory for an int array of size 5?
ANSWER: A
ANSWER: C
Which of the following is correct to deallocate a memory for an int array of size 5?
B. delete pointer;
D. delete;
ANSWER: A
ANSWER: A
Which operator allocates storage of the proper size for an object at execution time?
A. new
B. create
C. init
D. allocate
ANSWER: A
If a pointer of type double is declared (as shown below), which is the correct syntax to allocate
memory for 10 double variables?
double * ptr;
B. ptr=new [10]
C. ptr=new double[10]
D. Function overloading
ANSWER: A
D. None of these
ANSWER: C
ANSWER: C
B. It is written in modules
ANSWER: D
B. Inability to tweak details which may affect performance or the desired output
D. All of these
ANSWER: D
A. Generalizable or generic
B. Easily extendibles
C. Both A and B
D. None of these
ANSWER: C
A. Functions or subroutines
C. Polymorphism
D. Algorithms
ANSWER: D
In a C++ class, which feature enables the user to pass different data types as arguments to the same
function?
A. polymorphism
B. encapsulation
C. member function
D. inheritance
ANSWER: A
When a class is implemented as an ADT, which of the following should normally be true ?
ANSWER: B
A. int
B. Queue
C. double
ANSWER: B
A reference is not
B. a pointer
ANSWER: B
A. .
B. ->
C. ~
ANSWER: B
A. Comma operator
ANSWER: B
The major goal of inheritance in C++ is
ANSWER: C
A. late binding
B. early binding
C. dynamic allocation
ANSWER: A
A. Static binding
B. Early binding
C. Late binding
D. Runtime binding
ANSWER: C
A. abstract
B. Virtual
C. Dynamic
D. Typeid
ANSWER: B
A. Static binding
B. Runtime binding
C. dynamic binding
D. Easy binding
ANSWER: A
A. Early binding
B. Late binding
C. Both A & B
D. Neither A nor B
ANSWER: B
A. Only 1
B. Only 2
C. 1 and 2
D. Neither 1 nor 2
ANSWER: C
ANSWER: C
A. Dynamic polymorphism
B. Dynamic binding
C. Both A & B
D. Compile-time polymorphism
ANSWER: C
A. Late Interpretation
B. Late Binding
C. Early Binding
D. Overloading
ANSWER: C
Which of the following concepts means determining at runtime what method to invoke?
A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
ANSWER: C
A program decides after it begins to run what function to execute in response to a statement such as
refToObject.func() is not an example of
A. polymorphism
B. late binding
C. early binding
D. virtual functions
ANSWER: C
A. Early binding
B. Static binding
C. Late binding
D. None
ANSWER: C
A. Early binding
B. Late binding
C. Virtual functions
D. Polymorphism
ANSWER: A
ANSWER: B
In which of the following mechanisms, types of all variables and expressions are fixed at compilation
time.
A. Strong Typing
B. Weak Typing
ANSWER: C
In which of the following mechanisms, types of all variables and expressions are decided at run time.
A. Strong Typing
B. Weak Typing
ANSWER: D
Direct function calls can be resolved through a process known as?
A. Early Binding
B. Dynamic Binding
C. Both A and B
D. Overloading
ANSWER: A
A. Identifiers
B. Classes
C. Pointers
D. Friend Class
ANSWER: A
B. Dynamic Binding
C. Static Binding
D. No special srvices
ANSWER: B
In which of the following mechanisms, types of all variables and expressions are not known until
runtime
A. Strong Typing
B. Weak Typing
ANSWER: D
Dynamic binding is necessary when we refer to derived class object with -----
A. Global pointer
B. Base class pointer
ANSWER: B
In which binding it is not possible to know which function will be called until runtime
A. Early Binding
B. Late Binding
C. Both A and B
ANSWER: B
ANSWER: C
A. Early Binding
B. Dynamic Binding
C. Both A and B
D. Overloading
ANSWER: B
A. Inheritance
B. Overloading
A. function variables
B. at class constructor
C. at friend function
ANSWER: B
A. Class
B. Structure
C. Enum
D. All of these
ANSWER: D
A. union
B. structure
C. class
D. array
ANSWER: C
D. to provide an appropriate base class from which other classes can inherit.
ANSWER: D
B. Assigning null
D. None of these
ANSWER: C
ANSWER: B
ANSWER: C
A. normal function
B. operator overloading
C. explicit function
D. inline functions
ANSWER: D
A. recurcive function
B. macros
C. call by value
D. structure
ANSWER: B
C. both a and b
D. neither a nor b
ANSWER: C
A. request to compiler
B. command to compiler
C. runtime error
ANSWER: A
A. it is normal function
ANSWER: B
D. both a and c
ANSWER: B
A static funct___________ members of the base class are never accessible by the deried class.
A. private
B. public
C. protected
D. all of these
ANSWER: A
Static variables are associated with class rather than with any class object so they are known as
A. local variable
B. global variable
C. class variable
D. either a or b
ANSWER: C
A. :
B. ;
C. #
D. none of these
ANSWER: B
Class cannot be
A. virtual
B. inline
C. generic
D. friend
ANSWER: B
A. Scope resolution
B. # operator
C. dot operator
D. none of these
ANSWER: C
If keyword struct is used instead of class then the access of the members will be
A. public by default
B. private by default
C. protected by default
D. none of these
ANSWER: A
A. nested class
B. derived class
C. subordinate class
D. none of these
ANSWER: C
A. int
B. double
C. char
D. class
ANSWER: D
In a class, member variables are often called as its______________ and member functions are called
its _______________
A. values,activities
B. data,actions
C. attributes,rules
D. attributes,methods
ANSWER: D
A. struct
B. union
C. both a and b
D. object
ANSWER: C
D. none of these
ANSWER: C
D. all of these
ANSWER: C
A. derived class
B. base class
C. both a and b
D. none of these
ANSWER: B
B. Member functions
C. both a and b
D. none of these
ANSWER: C
Which of the following allows you to create a derived class that inherits properties from more than
one base class
A. Multilevel inheritance
B. Multiple inheritance
C. Single inheritance
D. Hybrid inheritance
ANSWER: B
Parent:child is
A. base:derived
B. derived:driven
C. chid:super
D. subclass:superclass
ANSWER: A
A. Class class_name
D. None of these
ANSWER: C
D. none of these.
ANSWER: B
A. dot
B. comma
C. hash #
D. dollar
ANSWER: B
In public inheritance
A. code reusability
C. subtyping
ANSWER: D
ANSWER: A
A. Only 1
B. Only 2
C. Both
D. None
ANSWER: C
A. Access specifiers
B. Format specifiers
C. Visibility labels
D. Both A&C
ANSWER: D
B. By member functions
C. Both
D. None
ANSWER: B
Which of the following statements are correct I) Private member functions can be called by another
member function II) An object can access the private variables using dot operator in main
A. Only I
B. Only II
C. Both
D. None
ANSWER: A
A static member
C. Visible only within the class but lifetime is the entire program
D. All of these
ANSWER: D
Which of the following is correct?
A. Can have access to only static members declared in the same class
D. can have access to all the public members in all the classes
ANSWER: A
A friend function
C. Can access the member names using an object name and a dot membership operator
ANSWER: C
Classes can be defined and used inside a function which are known as
A. Inbuilt classes
B. Inline classes
C. Local classes
D. Enclosed classes
ANSWER: C
B. Default constructor
C. Copy constructor
D. Void constructor
ANSWER: B
Which of the following statements are wrong
ANSWER: C
A _______ constructor takes a reference to an object of the same class as itself as an argument
A. Reference constructor
B. Copy constructor
C. Self constructor
D. None of these
ANSWER: B
D. All of these
ANSWER: D
State true or false I. A destructor never takes any argument nor does it return any value II. It releases
memory space for further use
A. True,true
B. True, false
C. False,true
D. False,false
ANSWER: A
Automatic initialization of the of object is carried out using a special member function called
A. Friend
B. Casting
C. Reference parameter
D. Constructor
ANSWER: D
D. None of these
ANSWER: B
D. Both a&b
ANSWER: D
A. Static functions
B. Virtual functions
C. Inline functions
D. None
ANSWER: C
C. Both
D. None
ANSWER: A
A. Always inline
B. Not line
C. Private
ANSWER: A
A. That pointer
B. This pointer
C. Address pointer
D. None
ANSWER: B
C. Class is declared
D. None of these
ANSWER: B
D. None of these
ANSWER: B
In which of the ways can a class be privately inherited <br>1. Class A:private B <br>2. Class
A:protected B <br>3. Class A: B <br>4. Class <br> A:public B
A. 1
B. 1,2,3
C. 1,3
D. 1,2,3,4
ANSWER:C
A. function declaration
B. function definition
C. main function
ANSWER: A
B. friend class;
C. friend class
ANSWER: A
ANSWER: C
What are the things are inherited from the base class?
C. Friends
ANSWER: D
C. both a & b
Answer:a
A. template parameters
C. template type
Answer:b
Explanation:During runtime, We can choose the appropriate type for the function
A. you only need to write one function, and it will work with many different
types.
Answer:a
Explanation:Because of template type parameters, It will work with many types and saves a lot of
time.
#include <iostream>
template
int main()
int p;
p = Max(100, 200);
return 0;
A. 100
B. 200
C. 300
D. 100 200
Answer:b
Explanation:In this program, We are returning the maximum value by using function template.
Output:
$ g++ ftemp.cpp
$ a.out
200
template
class Test
public:
Test()
};
~Test()
};
return Var1;
return Var2;
};
int main()
Test Var1;
Test Var2;
return 0;
A. 200 3.123
B. 3.123 200
C. 200
D. 3.123
Answer:a
Explanation:In this program, We are passing the values and getting it back from template. And we
are
Output:
$ g++ ftemp1.cpp
$ a.out
200
3.123
#include <iostream>
template
class TestVirt
public:
return Var1 * 2;
};
int main()
TestVirt Var1;
return 0;
}
A. 100
B. 200
C. 50
Answer:b
Explanation:In this program, We are using class to pass the value and then we are manipulating it.
Output:
$ g++ ftemp3.cpp
$ a.out
200
#include <iostream>
template
inline T square(T x)
T result;
result = x * x;
return result;
};
int main()
int i, ii;
float x, xx;
double y, yy;
i = 2;
x = 2.2;
y = 2.2;
ii = square(i);
cout << i << "" << ii << endl;
yy = square(y);
A. 2 4 2.2 4.84
B. 2 4
C. error
D. runtime error
Answer:a
Explanation:In this program, We are passing the values and calculating the square of the value by
Output:
$ g++ ftemp4.cpp
$ a.out
24
2.2 4.84
#include <iostream>
template
void loopIt(T x)
T val[count];
val[ii] = x++;
};
int main()
float xx = 2.1;
loopIt(xx);
A. 2.1
B. 3.1
C. 3.2
Answer:d
Explanation:In this program, We are using the for loop to increment the value by 1 in the function
template.
Output:
$ g++ ftemp5.cpp
$ a.out
2.1
3.1
4.1
A. int
B. float
C. constant expression
Answer:c
compile time. The constant expression may also be an address of a function, object or static class
member.
From where does the template class derived?
B. templated class
C. a or b
Answer:c
A. class
B. typename
C. both a & b
D. function
C. whole program
#include <iostream>
class mysequence
T memblock [N];
public:
};
memblock[x] = value;
return memblock[x];
int main ()
return 0;
A. 100
B. 3.1416
C. 100 3.1416
D. none of the mentioned
Answer:c
Explanation:In this program, We are printing the integer in the first function and float in the second
function.
Output:
$ g++ farg.cpp
$ a.out
100 3.1416
#include <iostream>
T max (T a, T b)
return (a>b?a:b);
int main ()
int i = 5, j = 6, k;
long l = 10, m = 5, n;
k = max(i, j);
n = max(l, m);
return 0;
A. 6
B. 6 10
C. 5 10
D. 6 5
Answer:b
Explanation:In this program, We are using the ternary operator on the template function.
Output:
$ g++ farg.cpp
$ a.out
6 10
#include <iostream>
class Test
public:
Test()
};
~Test()
};
return Var1;
return Var2;
};
int main()
Test<int> Var1;
Test<double> Var2;
return 0;
A. 100
B. 200
C. 3.123
D. 200 3.123
Answer:d
Explanation:In this program, We are passing the value and returning it from template.
Output:
$ g++ farg3.cpp
$ a.out
200 3.123
#include <iostream>
void loopIt(T x)
T val[count];
val[ii] = x++;
};
int main()
float xx = 2.1;
loopIt<float, 3>(xx);
A. 2.1
B. 3.1
C. 4.1
Answer:d
Explanation:In this program, We are using the non-type template parameter to increment the value
in
Output:
$ g++ farg4.cpp
$ a.out
2.1
3.1
4.1
A. binding
B. rebinding
C. both a & b
D. none of these
Answer:c
A. pointer to member
B. object
C. class
Answer:a
Explanation:The following are legal for non-type template parameters:integral or enumeration type,
member.
A. functions
C. member class
Answer:d
Explanation:The compiler does not generate definitions for functions, non virtual member functions,
Answer:a
A. class
B. typename
C. both a & b
D. function
Answer:c
C. whole program
Answer:a
#include <iostream>
class mysequence
T memblock [N];
public:
};
memblock[x] = value;
}
return memblock[x];
int main ()
return 0;
A. 100
B. 3.1416
C. 100 3.1416
Answer:c
Explanation:In this program, We are printing the integer in the first function and float in the second
function.
Output:
$ g++ farg.cpp
$ a.out
100
3.1416
T max (T a, T b)
return (a>b?a:b);
int main ()
int i = 5, j = 6, k;
long l = 10, m = 5, n;
k = max(i, j);
n = max(l, m);
return 0;
A. 6
B. 6 10
C. 5 10
D. 6 5
Answer:b
Explanation:In this program, We are using the ternary operator on the template function.
Output:
$ g++ farg.cpp
$ a.out
10
class Test
public:
Test()
};
~Test()
};
return Var1;
return Var2;
};
int main()
Test<int> Var1;
Test<double> Var2;
return 0;
A. 100
B. 200
C. 3.123
D. 200 3.123
Answer:d
Explanation:In this program, We are passing the value and returning it from template.
Output:
$ g++ farg3.cpp
$ a.out
2003.123
#include <iostream>
void loopIt(T x)
T val[count];
val[ii] = x++;
};
int main()
float xx = 2.1;
loopIt<float, 3>(xx);
A. 2.1
B. 3.1
C. 4.1
D. 2.1
Answer:d
Explanation:In this program, We are using the non-type template parameter to increment the value
in the
function template.
Output:
$ g++ farg4.cpp
$ a.out
2.1
3.1
4.1
A. binding
B. rebinding
C. both a & b
D. none of these
Answer:c
A. pointer to member
B. object
C. class
Answer:d
Explanation:The compiler does not generate definitions for functions, non virtual member functions,
class
C. both a & b
Answer:a
A. template parameters
C. template type
Answer:b
Explanation:During runtime, We can choose the appropriate type for the function
A. you only need to write one function, and it will work with many different
types.
#include <iostream>
template
type Max(type Var1, type Var2)
int main()
int p;
p = Max(100, 200);
return 0;
A. 100
B. 200
C. 300
D. 100
Answer:b
Explanation:In this program, We are returning the maximum value by using function template.
Output:
$ g++ ftemp.cpp
$ a.out
200