C++ Based Questions
C++ Based Questions Questions for BCA, MCA Entrance and Placement Papers Preparation and Practice
Questions
How many arguments do destructors take?
- Two
- One
- Infinite
- None
A pure virtual function is a function that___________
- has no body
- returns nothing
- is used in a base class
- takes no arguments
When we pass arguments by reference, the formal arguments in the called function become aliases to the actual arguments in the calling function.
- True
- False
The last character in a string must be_________
- 0 (zero)
- - (null)
- empty
- none of the above
A constructor that accepts no parameters is called the ___________
- dynamic constructor
- parameterized constructor
- default constructor
- none of the above
A _______________ function can access a class private data, even though it is not a member function of the class.
- friend
- static
- virtual
- abstract
What is the result of the following statement?
cout<<sizeof(float);
- 4.000000
- 2
- 4
- 8
Which one of the following is a bitwise operator?
- !
- ~
- ==
- !=
Which one of the following is a valid method for accessing the 3rd element of the array cust?
- cust.3
- cust[3]
- cust[2]
- cust(2)
A function template definition begins with the keyword___________
- template
- class
- namespace
- class template
A C++ array can store values of different data types.
- True
- False
A pointer is a variable for storing
- integer values
- address of another variable
- its own address
- none of the above
What is the output of the following code?
int a=0;
for(int I=1;I<=a;I++)
cout<<I;
- 0
- 1
- Nothing will get displayed
- Error
What is the output of the following program?
#include<iostream.h>
void x(int a,int &b)
{
a=a+b;
a=a-b;
b=b-a;
}
void main()
{
int a=4,b=10;
x(a,b);
cout<<a<<b;
}
- 4, 10
- 10, 4
- 4, 4
- 4, 6
A constructor's name is same as __________
- function name
- class name
- function name or class name
- none of the above
Which manipulator is used to specify the required field size for displaying an output value?
- setfill()
- setprecision()
- setw()
- setiosflags()
A datatype that allows different data types to be assigned to the same storage location is called_________.
- enum
- union
- array
- none of the above
If p and q are int type variables, what will be the result of the following expression?
p % q
Where p = - 16 and q = - 3
- 1
- -1
- 5
- -5
The following examples show that the class R id derived from classes P and Q. Which of them is/ are legal?
- class R : public P : public Q
- class R : public P, Q
- class R : public P, public Q
- class R :: public P : public Q
The wrapping up of data and functions into a single unit is called _____________
- inheritance
- abstraction
- polymorphism
- encapsulation
Can class objects be passed to a function?
- Yes
- No
What is the value of a & b after the following two statements are executed?
int a=10;
int b=a++ * ++a;
- 132
- 110
- 120
- None of the above
Which one of the following is overloading the function?
int sum(int x,int y) {}
- int sum(int x,int y,int z) {}
- float sum(int x,int y) {}
- int sum(int a,int b) {}
- all of the above
The default case is required in the switch selection structure.
- Yes
- No
Opening a file in ios::out mode also opens it in the __________ mode by default.
- ios::app
- ios::in
- ios::trunc
- ios::nocreate