MCQ related to Object Oriented programming using C++ for general use and also for job preparation of Public Service Commission
A function abc is defined as
void abc (int x =0, int y, int z=0)
{
cout << x << y << z ;
}
which of the following function calls is/are illegal? (Assume h , g are declared as integers)
Option 1
|
abc ( ) ; |
Option 2
|
abc (h) ; |
Option 3
|
All of these |
Option 4
|
None of the these |
int a=1, b=2;
a=chg(b);
cout <<a<<b;
If the function chg is coded as
Int chg (int x)
{
x=10;
retrun(11);
}
Then
Option 1
|
It results in compile-time error |
Option 2
|
It results in run time error |
Option 3
|
It prints 112 |
Option 4
|
It prints 1110 |
int a=1, b=2;
a=chg(b);
cout <<a<<b;
If the function chg is coded as
int chg (int &x )
{
x =10;
return(11);
}
Then
Option 1
|
It results in compile-time error |
Option 2
|
It result in run time error |
Option 3
|
It prints 112 |
Option 4
|
It prints 1110 |
int a=1, b=2;
a=chg(b);
cout <<a<<b;
If the function chg is coded as
int chg(const int &x)
{
x=10;
return (11)
}
Then
Option 1
|
It results in compile-time error |
Option 2
|
It result in run time error |
Option 3
|
It prints 112 |
Option 4
|
It prints 1110 |
Consider the follwing program segment:
const char *p1=”To make the bitter butter better“; // stm1
char *const p2= “ Recommend this book 2 others“; // stm2
p1= “add some better butter not bitter“; //stm3
p2="so that they 2 will get benefited."; //stm4
*(p1+3)=’A’ ; //stm5
*(p2+3)=’A’; // stm6
Which of the statement results in error?
Option 1
|
Stm4 and stm5 |
Option 2
|
Stm1 and stm2 |
Option 3
|
Stm1 and stm4 |
Option 4
|
Stm2 and stm3 |
The following program
void abc (int &p)
{cout << p; }
void main (void )
{
float m = 1.23;
abc (m);
cout << m ;
}
Option 1
|
Result in compilation error |
Option 2
|
Results in run time error |
Option 3
|
Prints 1.23 |
Option 4
|
Prints 1 |
choose the best answer:
A function that does the same operation on different data types is to be implemented using
Option 1
|
Macros |
Option 2
|
Overloading |
Option 3
|
Function templates |
Option 4
|
Default arguments |
What is the output of the following C++program?
void abc( int x=0, int y=0)
{
cout <<“Hi There“;
}
void abc(int x)
{
cout <<”How R U doing today?":
}
void main (void)
{
int m=5;
abc(m);
}
Option 1
|
Hi there |
Option 2
|
How R U doing today? |
Option 3
|
Wat gets printed depends on how the particular compiler is implemented |
Option 4
|
It results in compilation error |
Consider the declarations
char a;
const char aa=‘h’;
char *na;
const char *naa;
Which of the following statements is/are illegal?
Statement I: aa = a;
Statement II: na= &a;
Statement III: na=&aa;
Option 1
|
Only I and II |
Option 2
|
Only II and III |
Option 3
|
Only I and III |
Option 4
|
All the three statements are illegal |
#include ‘’iostream.h’’
int a(int m)
{ return ++m; }
int b(int &m)
{ return ++m; }
int c(char &m)
{ return ++m; }
void main( )
{
int p=0, q=0 , r=0;
p+=a (b(p));
q+ =b(a (q));
r+=a (c(r));
cout <<p<<q<<r;
}
The above program prints:
Option 1
|
Results in compilation error |
Option 2
|
Prints 123 |
Option 3
|
Prints 111 |
Option 4
|
Prints 322 |