Monday, March 22, 2021

C++ PROGRAMMING QUESTION SET (1 TO 50 )

 


C++ PROGRAMMING QUESTION SET (1 TO 50 )

visit our website www.itcorner.org.in  for more info 






1)   We can prevent a function from throwing any exceptions.

a. True 
b. False

Ans1: A

2)   Functions called from within a try block may also throw exception.

a. True
b. False

Ans2: A

 

3)   The explicit keyword is an optional decoration for the constructors that takes exactly_____argument.

a. No argument 
b. Two 
c. Three
d. One 

Ans3: C

 

4)   A class can contain objects of other classes and this phenomenon is called_________ .

a. Relationship
b. Object Association 
c. Containership 
d. None of these 

Ans4: D

5)   Can we alter/modify the values of data members of a class inside const member function?

a. Yes
b. No

Ans5: A

 

6)    If a class contains pure virtual function, then it is termed as____________________ .

a. Virtual class 
b. Sealed class 
c. Pure Local class 
d. Abstract Class 

Ans6: D

 

7)   If inner catch handler is not able to handle the exception then__________ .

a. Compiler will look for outer try handler
b. Program terminates abnormally
c. Compiler will check for appropriate catch handler of outer try block
d. None of these

Ans7: C

 

8)   Generic catch handler is represented by ______________ .

a. catch(..,) 
b. catch(---)
c. catch(…) 
d. catch( void x)

Ans8: C

 

9)   Which one is suitable syntax for function template?

a. template< class T> return_type Function_Name(parameters)
b. template< typename T> return_type Function_Name(parameters)
c. both a and b 
d. None of these

Ans9: C

 

10)   It is not possible to combine two or more file opening mode in open () method.

a. True
b. False

Ans10: B

 

11)   Private members of the class are not inheritable.

a. True
b. False

Ans11:B

12)   While overloading binary operators using member function, it requires ___ argument/s.

a. Zero
b. One 
c. Two 
d. Three

Ans12: B

 

13)   If abstract class is inherited by derived class, then_______________ .

a. Derived class should provide definition for all the pure virtual functions
b. Derived class also become abstract if fails to implement pure virtual functions
c. Objects of derived class can’t be created if it fails to implement pure virtual functions
d. All of these 

Ans13: D

 

14)    By default, all the files are opened in ___________mode .

a. Binary 
b. Text 
c. Can’t say

Ans14: B

15)   The CPP compiler supports automatic type conversions for the user defined datatypes.

a. True
b. False

Ans15: B

16)   An exception can be of only built-In type.
a. True
b. False
Ans16: B

 

 

 17)Which of the following type of class allows only one object of it to be created?

A)

Virtual class

B)

Abstract class

C)

Singleton class

D)

Friend class

 

Ans17: C

 

 

18)   Can a class be declared/defined inside another class ?

a. Yes 
b. No

Ans18: A

 

19)   Can we pass parameters to base class constructor though derived class or derived class constructor?

a. Yes
b. No

Ans19: A

 

20)   _________________are used for generic programming.

a. Inheritance 
b. Virtual Functions 
c. Templates
d. None of these

Ans20: C

 

 

 

 

 

 

 21)Which of the following type of class allows only one object of it to be created?

A)

Virtual class

B)

Abstract class

C)

Singleton class

D)

Friend class

 

Ans21: C

22.)Which of the following is not a type of constructor?

A.)

Copy constructor

B)

Friend constructor

C)

Default constructor

D)

Parameterized constructor

 

 

Ans22: B

 

23)Which of the following is not the member of class?

A)

Static function

B)

Friend function

C)

Const function

D)

Virtual function

 

Ans23: C

 


24)Which of the following concepts means determining at runtime what method to invoke?

A)

Data hiding

B)

Dynamic Typing

C)

Dynamic binding

D)

Dynamic loading

Ans24 :C


25)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

Ans25: C



 

26.What is the output of following.

#include<iostream.h>

#include<conio.h>

 

class Test

{

  static int i;

  int j;

};

  

int Test::i;

  

int main()

{

    cout<<sizeof(Test);

    return 0;

}

 

 

A)compile Error

B)4

C)2

D)0

 

Ans26: C

 

 

 

 

 

27)Predict the output

 

#include<iostream.h>

#include<conio.h>

 

class Base1 {

 public:

     Base1()

     { cout<< "I am BASE1 " <<endl;  }

};

  

class Base2 {

 public:

     Base2()

     { cout<< " I am BASE2 " <<endl;  }

};

  

class Derived: public Base1, public Base2 {

   public:

     Derived()

     {  cout<< "I am DERIVED" <<endl;  }

};

  

int main()

{

   Derived d;

   return 0;

}

 

A)I am BASE1
I am BASE2
   I am DERIVED

 

B) I am DERIVED

   I am BASE1
I am BASE2

 

c)I am BASE1
I am BASE2

D)I am BASE1
I am BASE2
   I am DERIVED

   I am BASE1
I am BASE2

 

Ans27: C

 

 

28)Predict output

#include<iostream.h>

int main()

{

    intx = 1,y= 1;

    cout<< ( ++x && ++y ) <<endl;     

    cout<< x << " "<<y;             

    return 0;

}

 

A)1

  1 2

B)1

  1 1

C)1

  2 2

D)None

 

 

 

Ans28: C

 

29) If a class contains pure virtual function, then it is termed as____________________ .

A. Virtual class 
B. Sealed class 
C. Pure Local class 
D. Abstract Class 

Ans29: D

 

 

 

 

 

 

30)Predict Output

#include<iostream.h>

class Rectangle

{          

int L,B;

public:

Rectangle()

{

L=10;

B=20;

}

 class Square;  

};

class Square

{

int S;

public:

Square()

{

S=5;

}

void Display(Rectangle Rect)

{

cout<<"\n\n\tLength : "<<Rect.L;

cout<<"\n\n\tBreadth : "<<Rect.B;

cout<<"\n\n\tSide : "<<S;

}

            };

            void main()

            {

Rectangle R;

Square S;

S.Display(R);      

}

 

A) Length : 10

    Breadth : 20

   Side : 5

B)Comile Error

C)  Length : 15

    Breadth : 20

 Side : 5

D)  Length : 10

       Breadth : 25

     Side : 5

Ans30: A

 

 

 

 

 

 

31)   Which of the followings is/are pointer-to-member declarator?

A. ->
B. .* 
C. ::* 
D. both a and b 

Ans31: D

 

32)   Which of the following is CPP style type-casting?

A. per = total/(float)m
B. per = total/float(m)
C. per = (float)total/m 
D. None of these

Ans32: C

 

33) #include<iostream.h>

            #include<conio.h>

 

            int Add(int x, int y=20, int z=30)

            {

              return x + y + z;

}

void main()

            {

 

                        intrs;

 

                        rs = Add(5);

                        cout<<"\n\tThe sum is : "<<rs;

 

                        rs = Add(4,8);

                        cout<<"\n\tThe sum is : "<<rs;

 

                        rs = Add(7,3,4);

                        cout<<"\n\tThe sum is : "<<rs;

            }

 

A)The sum is:55

The sum is:42

The sum is:14

 

B)The sum is:55

The sum is:42

The sum is:11

 

C)The sum is:57

The sum is:42

The sum is:14

D)NOTA

Ans33: C

 

 

 

 

 

 

34)   If a program uses Inline Function, then the function is expanded inline at ___________.

A. Compile time 
B. Run time 
C. Both a and b 
D. None of these

Ans34: B

 

35)   Which of the following is the perfect set of operators that can’t be overloaded in CPP ?

A. +=, ?, :: , >> 
B. >>, <<, ?, *, sizeof()
C. :: , . , .* , ?: 
D. :: , ->, * , new, delete

Ans35: C

 

 

36)   Syntax for Pure Virtual Function is ______________ .

A. virtual void show()==0 
B. void virtual show()==0
C. virtual void show()=0
D. void virtual show()=0

Ans36: C

 

37)  which keyword is used to define the macros in c++?
A) macro
B) define
C) #define
D) none of the mentioned

Ans37: C

 

 

 

38)  What is the output of this program?

#include <iostream.h>

usingnamespacestd;

#define MIN(a,b) (((a)<(b)) ? a : b)

int main ()

{

float i, j;

        i =100.1;

        j =100.01;

cout<<"The minimum is "<< MIN(i, j)<<endl;

return0;

}

A)100.01
B)100.1
C)compiletimeerror
D) none of the mentioned

Ans38: A

 

39) How many specifiers are present in access specifiers in class?
A)1
B)2
C)3
D) 4

Ans39: A

 

 

 

 

40) What is the output of this program?

#include <iostream.h>

classrect

{

int x, y;

public:

voidval(int, int);

int area ()

{

return(x * y);

}

};

voidrect::val(int a, int b)

{

        x = a;

        y = b;

}

int main ()

{

rectrect;

rect.val(3, 4);

cout<<"rect area: "<<rect.area();

return0;

}

A)rectarea:24
B)rectarea:12
C) compile error because rect is as used as class name and variable name in line #20
D) none of the mentioned

Ans40: B

 

41) Constructors are used to
A) initialize the objects
B) construct the data members
C) both initialize the objects & construct the data members
D) none of the mentioned

Ans41: C

 

42) 1. What is the user-defined header file extension in c++?
A) cpp
B) h
C) hf
D) none of the mentioned

Ans42: B

 

43) What is the output of this program?

#include <iostream.h>

int main()

{

char name[30];

cout<<"Enter name: ";

gets(name);

cout<<"Name: ";

puts(name);

return0;

}

A)jobsjobs
B)jobs
C)compiletimeerror
D) program will not run

Ans43: C

 

44) setprecision requires which of the following header file?
A) stdlib.h
B) iomanip.h
C) console.h
D) conio.h

Ans44: C

 

45) What is the output of this program?

#include <iostream.h>

#include <string.h>

int main ()

{

char str1[10]="Hello";

char str2[10]="World";

char str3[10];

intlen;

strcpy( str3, str1);

strcat( str1, str2);

len=strlen(str1);

cout<<len<<endl;

return0;

}

A)5
B)55
C)11
D) 10

Ans45: D

 

46)  Which of the following is correct about static variables?
A) Static functions do not support polymorphism
B) Static data members cannot be accessed by non-static member functions
C) Static data members functions can access only static data members
D) Static data members functions can access both static and non-static data members

Ans46: D

 

47)  It is guaranteed that a ____ has at least 8 bits and a ____ has at least 16 bits.
A) int, float
B) char, int
C) bool, char
D) char, short

Ans47: B

 

48).Which ofthe following will not return a value?
A)null
B)void
C)empty
D)free


Ans48: B

 

49.____havethereturntypevoid?
A)allfunctions
B)constructors
C)destructors
D) none of the mentioned

Ans49: C

 

 

50)Choose the incorrect option
A)void is used when the function does not return a value
B)void is also used when the value of a pointer is null
C)void is used as the base type for pointers to objects of unknown type
D)void is a special fundamental type

 

Ans50: C

 

 



No comments:

Post a Comment

cprogramminginmarathi

C Programmin Marathi Notes Chapter 1. Introduction C History Of C :       १९९६ च्या दशकाच्या उत्तराध्रारात operating system आणि hardware याव...