C++ Objective Questions (page 1 of 6)

Question: 1

How many loops are there in C++ 98?

(A) 2
(B) 3
(C) 4
(D) 1

Compiler  Forum
[ Beginner : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 2

What is the output of below program?

int main()
{
 if(0)
 {
    cout<<"Hi";
 }
 else
 {
    cout<<"Bye";
 }
return 0;
}

(A) Hi
(B) Bye
(C) HiBye
(D) Compilation Error

Compiler  Forum
[ Beginner : conditional ] [ Posted by - Admin : Chicago, USA ]


Question: 3

What following operator is called 
?:

(A) Scope Resolution Operator
(B) Conditional Operator
(C) Ternary Operator
(D) if else o/p

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 4

What is size of int data type in cpp?

(A) 2 Bytes
(B) 4 Bytes
(C) 1 Byte
(D) Depends on Compiler

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 5

Which operator can not be overloaded?

(A) +
(B) -
(C) *
(D) ::

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 6

Which operator has more precedance  in below list?

(A) +
(B) -
(C) ++
(D) *

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 7

What should be the output of below program?

int main()
{
int a=10; cout<<a++;
return 0;
}

(A) 11
(B) 10
(C) Error
(D) 0

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 8

Can we typecast void into int?

(A) Yes
(B) No
(C) Undefined
(D) Depends on Compiler

Compiler  Forum
[ Practitioner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 9

What is currect syntax of for loop?

(A) for(initialization;condition; increment/decrement)
(B) for(increment/decrement; initialization; condition)
(C) for(initialization, condition, increment/decrement
(D) None of These

Compiler  Forum
[ Beginner : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 10

#include<iostream.h>
void Execute(int &x, int y = 200)
{
 int TEMP = x + y;
 x+= TEMP;
 if(y!=200)
     cout<<TEMP<<x<<y"--";
}

int main()
{
 int A=50, B=20;
 cout<<A<<B<<"--";
 Execute(A,B);
 cout<<A<<B<<"--";
 return 0;
}

(A) 5020--5020--
(B) 5020--7012020--12020--
(C) 5020--70120200--5020
(D) 5020--7050200--5020--

Compiler  Forum
[ Practitioner : function ] [ Posted by - Admin : Chicago, USA ]


Question: 11

Can we overload functions in C++?

(A) Yes
(B) No
(C) Compilation Error
(D) Runtime Error

Compiler  Forum
[ Beginner : function ] [ Posted by - Admin : Chicago, USA ]


Question: 12

How many times CppBuzz.com is printed?

int main()
{
    int i=0;
    lbl:
    cout<<"CppBuzz.com";
    i++;
    if(i<5)
    {
	goto lbl;
    }
return 0;

}

(A) Error
(B) 5 times
(C) 4 times
(D) 6 times

Compiler  Forum
[ Practitioner : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 13

What is output of below program?
int main()
{
  const int a=10;
  a++;
  cout<<a;
return 0;

}

(A) 10
(B) 11
(C) Compilation Error
(D) Linking Error

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 14

How to access and edit data in data file handling using structures

(A) read()
(B) write()
(C) both A and B
(D) without read()

Compiler  Forum
[ Practitioner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 15

Which operator has highest precedence in * / % ?

(A) *
(B) /
(C) %
(D) all have same precedence

Compiler  Forum
[ Practitioner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 16

Which operator has highest precedence?

(A) ()
(B) =
(C) *
(D) ++

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 17

What ise value of a in below program?

void main()
{
 int a, b=20;
 a = 90/b;
}

(A) 4.5
(B) 4.0
(C) 4
(D) Compilation Error

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 18

class base
{
public:
       base()
       {          
           cout<<"BCon";
       }
       ~base()
       {
	   cout<<"BDest ";
       }
};
class derived: public base
{
public:
       derived()
       {     cout<<"DCon ";
       }
       ~derived()
       {     cout<<"DDest ";
       }
};

int main()
{
derived object;
return 0; 
}

(A) Dcon DDest
(B) Dcon DDest BCon BDest
(C) BCon DCon DDest BDest
(D) BCon DCon BDes DDest

Compiler  Forum
[ Beginner : classesAndobjects ] [ Posted by - Admin : Chicago, USA ]


Question: 19

What is the output of below program?

void main()
{
int a = 10;
cout<<a++;

}

(A) 10
(B) 11
(C) 12
(D) Not defined

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 20

What is the full form of oop

(A) Object oriented programming
(B) Oriented object programming
(C) Office oriented programming
(D) office objective programming

Compiler  Forum
[ Beginner : other ] [ Posted by - Admin : Chicago, USA ]


Question: 21

What is output of below program?

int main()
{
  int a=10;
  int b,c;
  b = a++;
  c = a;
  cout<<a<<b<<c;
  return 0;
}

(A) 111011
(B) 111111
(C) 101011
(D) 101010

Compiler  Forum
[ Beginner : operators ] [ Posted by - Admin : Chicago, USA ]


Question: 22

Can a for loop contain another for loop?

(A) No
(B) Yes
(C) Compilation Error
(D) Runtime Error

Compiler  Forum
[ Beginner : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 23

Can a Structure contain pointer to itself?

(A) Yes
(B) No
(C) Compilation Error
(D) Runtime Error

Compiler  Forum
[ Beginner : structure ] [ Posted by - Admin : Chicago, USA ]


Question: 24

What is size of void in bytes?

(A) 1
(B) 2
(C) 4
(D) 0

Compiler  Forum
[ Beginner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 25

Can any function call itself?

(A) Yes
(B) No
(C) Compilation Error
(D) Runtime Error

Compiler  Forum
[ Beginner : function ] [ Posted by - Admin : Chicago, USA ]


Question: 26

What should be the output of below program?

int main()
{
 cout<<"CppBuzz";;;;;  
 return 0;                                                                          
}

(A) Compilation Error
(B) Runtime Error
(C) CppBuzz
(D) CppBuzz;;;;

Compiler  Forum
[ Beginner : other ] [ Posted by - Admin : Chicago, USA ]


Question: 27

What should be the output?

int main() {
    int new = -10;
    cout<<"new is: "<<new;
    return 0;
}

(A) new is: -10
(B) new is: 10
(C) Compilation Error
(D) new is: 0

Compiler  Forum
[ Beginner : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 28

What should be the output of below program?

void main()
{
    int a = 1;
    switch(a)
    {
        case 1: cout<<"One";
        case 2: cout<<"Two";
        case 3: cout<<"Three";
        default: cout<<"Default";
    }

}

(A) One
(B) Compilation Error
(C) Default
(D) OneTwoThree

Compiler  Forum
[ Practitioner : conditional ] [ Posted by - Admin : Chicago, USA ]


Question: 29

What is size of void in C++?

(A) 2 Bytes
(B) 4 Bytes
(C) Undefined
(D) 0

Compiler  Forum
[ Expert : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 30

C++ is superset of which langauge?

(A) BASIC
(B) VB
(C) PASCAL
(D) C

Compiler  Forum
[ Beginner : other ] [ Posted by - Admin : Chicago, USA ]


Question: 31

class Mycpp
{
    int Mycpp()
    {
       cout<<"Constructor";
       return 0;
     }
};

void main()
{
    Mycpp obj;
}

(A) Constructor
(B) 0
(C) Compilation Error
(D) Runtime Error

Compiler  Forum
[ Beginner : classesAndobjects ] [ Posted by - Admin : Chicago, USA ]


Question: 32

class Mycpp
{
    
};

int main()
{
    Mycpp obj;
    return 0;
}

(A) Compilation Error - Constructor Missing
(B) Nothing would be printed
(C) Undefined
(D) In constructor

Compiler  Forum
[ Beginner : classesAndobjects ] [ Posted by - Admin : Chicago, USA ]


Question: 33

#include <iostream>
using namespace std;

class X
{
public: X()
        { cout<<"X"; }
        ~X()
        { cout<<"~X"; }
};

class Y : public X
{
public: Y()
        { cout<<"Y"; }
        ~Y()
        { cout<<"~Y"; }
};

int main()
{
    Y obj;
    return 0;
}

(A) XY~X~Y
(B) XY~Y~X
(C) X~XY~Y
(D) X~X~YY

Compiler  Forum
[ Expert : inheritance ] [ Posted by - Admin : Chicago, USA ]


Question: 34

#include<iostream>
using namespace std;

int main()
{

cout<<-1-1-1;

return 0;
}

(A) Compilation Error
(B) 0
(C) 3
(D) -3

Compiler  Forum
[ Beginner : other ] [ Posted by - Admin : Chicago, USA ]


Question: 35

When Virtual Table is created?

(A) Every Class has VTable
(B) Class inherited from other Class
(C) When a Class Overrides the function of Base class
(D) Class has atleast one Virtual Function

Compiler  Forum
[ Expert : vtable ] [ Posted by - Admin : Chicago, USA ]


Question: 36

How many object can be created of a Class in C++?

(A) 1
(B) 5
(C) There is no limit
(D) 256

Compiler  Forum
[ Beginner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 37

What is abstract class?

(A) A class with abstract keyword
(B) A class with no functions in it
(C) A class with atleast one pure virtual function
(D) Empty Class

Compiler  Forum
[ Practitioner : polymorphism ] [ Posted by - Admin : Chicago, USA ]


Question: 38

What is the size of empty class?

(A) 0
(B) 1
(C) 2
(D) 4

Compiler  Forum
[ Practitioner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 39

Can a class contain another class in it ?

(A) Yes
(B) No

Compiler  Forum
[ Practitioner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 40

Can we assign null to void pointer?

(A) No
(B) Yes

Compiler  Forum
[ Expert : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 41

Can we create our own workspace?

(A) Yes
(B) No

Compiler  Forum
[ Practitioner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 42

When can we have two classes with same name?

(A) We cant have
(B) In different work space
(C) Can have but in different file
(D) We can have in any scenario

Compiler  Forum
[ Practitioner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 43

Can we create array of reference?

(A) Yes
(B) No

Compiler  Forum
[ Practitioner : other ] [ Posted by - Admin : Chicago, USA ]


Question: 44

Exceptions are Caught at ?

(A) Compilation Time
(B) Run Time
(C) Linking Time
(D) No

Compiler  Forum
[ Expert : loops ] [ Posted by - Admin : Chicago, USA ]


Question: 45

Which of the following is Memory Leak detection tool?

(A) GC++
(B) KDevelop
(C) GIT
(D) Valgrind

Compiler  Forum
[ Expert : new_delete ] [ Posted by - Admin : Chicago, USA ]


Question: 46

Is const better than #define?

(A) Yes
(B) No

Compiler  Forum
[ Beginner : datatype ] [ Posted by - Admin : Chicago, USA ]


Question: 47

Is it good idea to return an address or a reference of a local variable? 

(A) Yes
(B) No

Compiler  Forum
[ Beginner : function ] [ Posted by - Admin : Chicago, USA ]


Question: 48

How to stop Name Mangling in C++?

(A) It is not possible
(B) It is possible only with C code
(C) By using extern "C" keyword
(D) By Converting C++ code to C

Compiler  Forum
[ Practitioner : function ] [ Posted by - Admin : Chicago, USA ]


Question: 49

Can we create object of Abstract class?

(A) Yes
(B) No

Compiler  Forum
[ Practitioner : abstract_class ] [ Posted by - Admin : Chicago, USA ]


Question: 50

Is there any difference in below two statements?

int a = 10;
int a(10);

(A) Yes
(B) No

Compiler  Forum
[ Beginner : datatype ] [ Posted by - Admin : Chicago, USA ]