C++ Ques For Practice PDF
C++ Ques For Practice PDF
Which of the following term is used for a function defined inside a class?
A. Member Variable
B. Member function
C. Class function
D. Classic function
Which of the following concepts of OOPS means exposing only necessary information to client?
A. Encapsulation
B. Abstraction
C. Data hiding
D. Data binding
cout is a/an :
A. operator
B. function
C. object
D. macro
(a) iostream
(b) conio
(c) stdio
(d) getch
Which of the following concept of oops allows compiler to insert arguments in a function call if it is not
specified?
A. Call by value
B. Call by reference
C. Default arguments
D. Call by pointer
D. Both A and B.
B. class data members are public by default while that of structure are private.
D. class data members are private by default while that of structure are public by default.
Which of the following concepts means wrapping up of data and functions together?
A. Abstraction
B. Encapsulation
C. Inheritance
D. Polymorphism
B. istream
C. ostream
D. ifstream
A. It speeds up execution.
D. Both A and C.
A. protected
B. public
C. private
D. friend
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.
D. Both A and B.
Which of the following statement will be correct if the function has three arguments passed to it?
A. Function call
B. Function definition
C. Function prototype
D. Both B or C
A-<
B-.
C-*
D - ::
#include<isotream>
using namespace std;
int main()
const int a = 5;
a++;
cout<<a;
A. 5
B. 6
D . Compile error
What is the size of the following union definition?(Assume int size is 2 Byte and char size is 1 Byte)
#include<isotream>
int main()
union abc
char a, b, c, d, e, f, g, h;
int i;
};
cout<<sizeof(abc);
return 0;
}
(a) 1 Byte
(b) 2 Byte
(c) 4 Byte
(d) 10 Byte
A. :=
B. =
C. equal
D. ==
A. float
B. real
C. int
D. double
A. */ Comments */
B. ** Comment **
C. /* Comment */
D. { Comment }
What is the correct value to return to the operating system upon the successful completion of a
program?
A. -1
B. 1
C. 0
(a) Write a Program in C++ to find largest among two number using class.
Write a Program in C++ to calculate area of circle,square,triangle and rectangle using function
overloading.
(a) Write a program in C++ to calculate simple interest by taking rate of interest as default argument.
(b) Write a program in C++ to swap two numbers using friend function.
UNIT II
What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and <-
D. ( and )
A. &&
B. &
C. ||
D. !
A. Only 1 is correct.
B. Only 2 is correct.
A. Pointer B. Structure
C. Macro D. Enum
a) *
b) &
c) ->
d) –>>
a) int *ip;
b) string s, *sp = 0;
d) int *pi = 0;
p = q;
a) b is assigned to a
b) p now points to b
c) a is assigned to b
d) q now points to a
#include <iostream>
int main()
char arr[20];
int i;
*(arr + i) = 65 + i;
*(arr + i) = '\0';
return(0);
a) ABCDEFGHIJ
b) AAAAAAAAAA
c) JJJJJJJJ
d) BBBBBBBBBB
#include <iostream>
int main()
{
char *ptr;
ptr = Str;
ptr += 5;
return 0;
a) fg
b) cdef
c) defg
d) abcd
a) int array[10];
b) int array;
c) array{10};
d) array array[10];
What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) 10
What is a array?
c) An array is a series of elements of the same type placed in non-contiguous memory locations
Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;
#include <stdio.h>
int main()
result += array1[temp];
}
result += array2[temp];
return 0;
a) 6553
b) 6533
c) 6522
d) 12200
#include <stdio.h>
int main ()
int n, result = 0;
result += array[n];
return 0;
}
a) 25
b) 26
c) 27
d) Garbage Value
#include <stdio.h>
int main()
return 0;
a) ABC
b) ABCD
c) AB
d) CBA
a) int
b) float
c) double
#include <iostream>
int main()
int a = 5, c;
void *p = &a;
double b = 3.14;
p = &b;
c = a + b;
return 0;
a) 8, memory address
b) 8.14
c) memory address
a) def
b) union
c) typedef
d) type
What is the output of this program?
#include <iostream>
int main()
num c = a + b + a - b;
cout << c;
return 0;
a) 20
b) 15
c) 30
d) 25
A) Reference
B) Pointer
C) Array
D) union
(c) constructor
(a) Array
(c) Object
(d) File
(a) delete
(b) new
(c) sizeof
(d) realloc
Write a program in C++ to implement linear search using class.
(b) Write a program in C++ to find maximum and minimum element from an array of 10 elements.
UNIT III
A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor
D. Initialize objects
(A) no argument
(A) 0
(B) 1
(C) 2
Given a class named Book, which of the following is not a valid constructor?
(A) Book ( ) { }
a. Custom
b. dynamic
c. static
d. default
If default constructor is not defined, then how the objects of the class will be created?
(a) 1,2
(b) 2,3
(c) 1,3,4,5
(d)1,2,3,5
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. both a and b
3. It can be virtual
a. Only 2, 3, 5
b. Only 2, 3, 4
c. Only 2, 4, 5
d. Only 3, 4, 5
a. <ifstream>
b. <ofstream>
c. <fstream>
d. <iostream>
a. ios::ate
b. ios::nocreate
c. ios::noreplace
d. ios::truncate
To create an output stream, we must declare the stream to be of class ___________ .
a. ofstream
b. ifstream
c. iostream
d. iostream
D) Program to Program
a. creating a file
b. reading a file
c. appending a file
d. removing a file
In the code fout.open("scores.dat", ios::out);
A. ofstream
B. ifstream
C. fstream
D. iostream
A. ios:app
B. ios::out
C. ios::in
D. ios::binary
B. myfile@close();
C. myfile:close();
D. myfile.close();
Which is among following is used to Open a file for output and move the read/write control to the end
of the file ?
A. ios::ate
B. ios::at
C. ios::ann
D. ios::end
A. One
B. two
C. No
D. three
Which of the following gets called when an object goes out of scope?
A. constructor
B. destructor
C. main
D. virtual function
Write a program in C++ to add two complex number using constructor overloading.\
(a) Explain the concept of Dynamic Constructor with help of suitable example.
UNIT IV
class B: public A
};
A.class A, class B
B.class B, class A
C.class B, class B
D.Cannot be determined
{
};
};
};
b) derived class
c) base class
Consider the math department of a school, which is made up of one or more teachers and the
department does not own the teachers (they merely work there), When the department is destroyed,
the teachers should still exist independently; this can be taken as an example of?
A. Aggregation
B. Composition
C. Inheritance
D. None of these
a. iterator
b. allocator
c. constructor
d. operator
Which of the following is the perfect set of operators that can’t be overloaded in CPP ?
a. +=, ?, :: , >>
c. :: , . , .* , ?:
d. None of these
A) +
B) ++
C) : :
D) = =
The derivation of Child class from Base class is indicated by ____ symbol.
a. ::
b. :
c. ;
d. |
a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c
Write a Program in C++ to perform addition of two complex numbers using binary operator overloading.
UNIT V
a) abstract class
b) derived class
c) base class
a) $
b) =0
c) &
d) !
#include<isotream>
main()
{
const int a = 5;
a++;
cout<<a;
A-5
B-6
C - Runtime error
D - Compile error
(c) constructor
(d) destructor
(a) new
(b) delete
(c) free
(d) malloc
(a) new
(b) delete
(c) free
(d) malloc
What is polymorphism
In order for an instance of a derived class to completely take over a class member from a base class, the
base class has to declare that member as
(a) new
(b) base
(c) virtual
(d) overrides
During dynamic memory allocation in CPP, new operator returns _________ value if memory allocation
is unsuccessful.
a. False
b. NULL
c. Zero
d. None of these
a. calloc()
b. malloc()
c. allocate
d. New
_______________ is a member function that is declared within a base class and redefined by derived
class.
a. virtual function
b. static function
c. friend function
a. Overloading
b. Overriding
c. Rewriting
d. All of these
Write a Program in C++ to implement concept of virtual function and give proper explanation.
Write a program in C++ to show use of new and delete operator and give proper explanation.
UNIT VI
a. Try
b. catch
c. throw
d. Finally
(a) 1,2,3
(b) 1,2
(c) 1,3
(d) only 3
An exception is caused by
a. A hardware problem
b. A problem in the operating system
c. A run-time error
d. A syntax error
(a) try
(b) rethrow
(c) throw
(d) catch
#include <iostream>
int main ()
try
{
throw 20;
catch (int e)
return 0;
a) 20
b) An exception occurred
c) error
d) An exception occurred 20
a) throw
b) try
c) catch
a) catch()
b) catch(Test t)
c) catch(...)
#include <iostream>
int main()
int x = -1;
try
if (x < 0)
throw x;
else
cout<<x;
catch (int x )
cout << "Exception occurred: Thrown value is " << x << endl;
return 0;
a) -1
b) 0
d) error
a) Size of vector
b) Type of vector
c) Number of elements
a) Uni-directional
b) Bi-directional
c) Multi-directional
Meaning of STL
#include <iostream>
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
Write a Program in C++ to add two numbers using the concept of function template.