Quick Google Search

C++ Questions for Aptitude Test


1)      The operator new creates objects in the ________
a)      stack memory
b)      heap memeory
c)      depends on the operating system
d)     both a)  and b)

2)      All global objects by default have the storage class _______
a)      auto
b)     static
c)      extern
d)     register

3)      Calling which of the following functions terminates the program without executing the destructors?
a)           exit()
b)          atexit()
c)           abort()
d)          there is no such function
  
4)      To deallocate an array of objects created using “new” which of the following should be used?
a)      delete
b)      free
c)      delete[ ]
d)     free[ ]

5)      A constructor cannot be declared as ___________
a)      Virtual
b)      Const
c)      Volatile
d)     All of the above        
     
6)      Which of the following is true for destructors?
a)      Destructors can be declared as const or volatile
b)      Destructors cannot be declared as static
c)      Destructors can be inherited
d)     All of the above

7)      Applying delete to a pointer not obtained from the “new” operator results in  ____________
a)      an exception
b)      compile time error
c)      run time error
d)     operation undefined

8)      Deriving a class from more than one base class is _________
a)      multilevel inheritance
b)     multiple inheritance
c)      hierarchial inheritance
d)     multipath inheritance

9)      _______ is the keyword used for overloading operators
a)      operators
b)      overload
c)      operator
d)     struct

10)  The member function to which the “this” pointer is not passed is to be declared as ____________
a)      Const
b)      Virtual

c)      Static

d)     Void

11)  On a turbo C++ compiler the operator sizeof(‘a’) returns__________
a)      2 bytes
b)      4 bytes
c)      1 byte
d)     C++ does’nt support sizeof operator

12) A class that has atleast one pure virtual function is a/an ___________
a)           pure virtual class
b)          virtual base class
c)           abstract base class
d)          friend class

13)      Consider the following code

class A
{ public:
A();
~A();
};
class B
{ public:
B();
       ~B();
};
class C:public B,public A
{ public:
              C();
~C() ;
};

What is the order in which the constructors will be called?
a.       C,B,A
b.      A,B,C
c.       B,A,C
d.      C,A,B

14)        In the above code, what is the order in which the desctructors will be called?
a)            A,B,C
b)            B,A,C

c)            C,A,B

d)           C,B,A

15)      A virtual function equated to zero is a ___________
a)           Null virtual function

b)          Pure virtual function

c)           Abstract function
d)          Static function

16)      What is the output of the following code?
class x
{ int size;
  public:
x();
       x( int size=256);
}
};
void main()
{ x alpha;
}
           
a)          compile time error
b)          runtime error
c)           no error
d)          program terminates abruptly

17)      Let class APE be a friend of class SAPIEN. Let class HUMAN be a child class of SAPIEN . Let class MONKEY   be a child class of APE. Which of the following is true about the above mentioned statements
a)           SAPIEN is not a friend of APE
b)          APE is not a friend of HUMAN
c)           MONKEY is not a friend of SAPIEN
d)          All  of the above

18)      To copy the contents of an object to another already existing object  ________ is used.
a)           the copy constructor
b)          the assignment operator
c)           a separate class
d)          a template

19)      Which of the following is true about a “const” member function?
a)           It cannot be invoked through a class object
b)           It cannot be invoked through a pointer to a class object
c)           It cannot cause a change in the state of the object
d)          All the above

20)      The default linkage of a constant data type in C & C++ respectively is ________ and ________.
a)           static, extern
b)          extern, static
c)           static, static
d)          extern, extrtern

21)      The “is-a” and “has-a” relationships respectively represent ________ and ________.
a)           Inheritance, polymorphism
b)          Inheritance, aggregation
c)           Inheritance, containment
d)          Both b) and c)

22)      Which of the following operators cannot be overloaded?
a)           ?:
b)          .
c)           >> 
d)          both a) and b)

23)      Overloading is an example of  _________.
a)           ad-hoc polymorphism
b)          compile time polymorphism
c)           run time polymorphism
d)          either a) or b)

24)      What is the result of executing the following code?

Class D
{ int size;
  public:
       D();
};
class B:public D
{ int x;
   public:
       B();
};
int main(void)
{ B B1;
}

a.       successful execution
b.      compile time error
c.       run time error
d.      a warning

25)      Consider the two classes “Aeroplane” and “cockpit”. Which of the following relationships holds good?
a)      Inheritance
b)     Aggregation
c)      Both a) and b)
d)     Neither a) or b)

26)      Which of the following is true about constructors and destructors?
a)            Both do not  return any value
b)           Constructors return a pointer to “this”, destructors don’t return anything
c)            Both of them return a pointer to “this”
d)           None of the above

27)      What is the result of the following code?
          Class f
                {  int a;
                   public:
              f(int a=8);
                 void show const()
                       { a=0;
            cout<<a;
}
};
void main()
{ f g;
  g.show();
}

a.       0
b.      8
c.       compile time error
d.      run time error

28)      What is the difference between “new” and “malloc” ?
a)      The return value of malloc is of type (void*) whereas the return value of new is a pointer to the constructed object
b)      malloc does not call constructors whereas new does
c)      Both a) and b)
d)     There is no difference

29)      Which of the following statements will flag an error?

Class b
{ public:
Virtual void foo() const ; //stm1
};
class d:public b
{ public:
virtual  void foo(); //stm2
};

                                                a)      only stm1
                                                b)      only stm2
                                                c)      both stm1 and stm2
                                               d)      compiler will just flag a warning

30)      Which of the following header files is used for exception handling?
a)         iostream.h
b)        iomanip.h
c)         stdlib.h
d)        limit.h

31)      What is the output of the following code?

Class c
{ volatile x;
   public:
       void show()
{ c=7.899;
  cout<<x;
}
};
void main()
{ c c1;
  c1.show();
}

                                          a)      7
                                          b)      7.899
                                          c)      7.9
                                         d)      Error in the declaration of x

32)      Which of the following statements will flag an error?

class myclass
{ public:
int d1=1; //stm1
int d2;
int d3;
myclass: d2(3) { d3=0;} //stm2

};

                                          a)      only stm1
                                          b)      only stm2
                                          c)      both stm1 and stm2
                                         d)      neither of them
                                   
33)      The default inheritance type is _________.
a)     Public

b)    Private

c)     Protected
d)    Public protected



34)      What is the output of the following code?

class d
{ public :
int x;
};
void main()
{ int *p;
  d d1;
  p=&d1.x;
}

a.       A warning
b.      -cannot convert ‘int d::*’ to ‘int*’
c.       No error
d.      None of the above

35)      What is the output of the following code?

                  Class d
          {public:
                 int x;
          };
          void main()
          { int *p;
            p=&d::x;
}

a)      A warning
b)     -cannot convert ‘int d::*’ to ‘int*’
c)      No error
d)     None of the above

36)      What is the output of the following code?
                 template <class T>
                 class array{
                 T *pt;
                 Int size;
                 Public:
                        array( int s);
                        ~array();
};
void main()
{ array arrayofints(100);
}

a)         No errors
b)        Invalid use of template array error
c)         Compiler warning
d)        None of the above

37)  Which of the following two classes is abstract?

         class base
{ public:
virtual void fn()=0;
};
class derived:public base
{
};

a)           only  base
b)           only derived
c)           both base and derived
d)          none of them

38)      While overloading the new operator the first argument must be of __________ type
                                          a)      sizet
                                          b)      size
                                          c)      size_t
                                         d)      char*

39)       Which of the following is called an exception handler?
                                          a)      try
                                          b)      throw
                                          c)      catch
                                         d)      none of the above

40)       A catch with three dots is _______
                                          a)      tricatch
                                          b)      ellipses
                                          c)      catchall
                                         d)      none of the above

41)       In the following statement, what does the function g() do?
int g() throw();

                                          a)      Throws an exception
                                         b)      Does not throw an exception
                                          c)      The declaration is syntactically wrong
                                         d)      None of the above

42)       If an exception is thrown but not caught which of the following function will be called ?
                                          a)      unexpected()
                                          b)      terminate()
                                          c)      abort()
                                         d)      All the above three functions will be called in turn

43)       The “operator<<” function returns a refernce to ________
                                          a)      istream
                                         b)      ostream
                                          c)      Both istream and ostream
                                         d)      None of the above

44)       The base class of ostream and istream is ________
                                          a)      eof
                                          b)      iof
                                          c)      ios
                                         d)      none of the above

45)       Which of the following functions is used to set up and break connections with istream and ostream?
a)      fill()
b)      width()
c)      tie()
d)     flush()

46)       Which of the following function indicates the default field size?
a)        width()
b)       width(0)
c)        fill()
d)       set()

47)        Which of the following function calls controls the adjustment of characters within a field?
                                          a)      width()
                                          b)      fill()
                                          c)      setf()
                                         d)      setg()

48)        Which of the following functions is used to position an ostream for writing?
                                         a)      flush()
                                        b)      seekp()
                                         c)      seekg()
                                        d)      tellg()

49)        Which of the following functions is used to denote a character position in a file?
                                         a)      seekp()
                                         b)      seekg()
                                         c)      tellp()
                                        d)      tell()

50)        Which of the following functions helps to determine the next character to be read?
                                         a)      seekg()
                                         b)      tellg()
                                         c)      peek()
                                        d)      getback()

51)       Which of the given statements is/are wrong?
                                                  i.      int operator+=(int val=0)
                                                ii.      myclass* operator .()
                                              iii.      int operator + (int,int)

a)         only i
b)        only ii
c)         only i and ii
d)        all of the above

52)        Which of the following two statements is/are true?
                                                              i.      Atleast one of the arguments to an overloaded operator must be of the class type
                                                            ii.      Only member functions may be const/volatile

a)           Only statement (i) is true
b)           Only statement (ii) is true
c)           Both (i) and (ii) are true
d)          Both (i) and (ii) are false

53)        Which of the following statements, on execution, will flag an error?


class base
              { private:
                     int d;
              };
              class derived: base
               { public:
              base::d; //stm1
               };
              void main()
              { derived obj1;
                obj1.d=0;//stm2
              }

a)              only stm1
b)             only stm2
c)              both stm1 and stm2
d)             neither of them



                                   





            

No comments:

Popular Posts