Sie sind auf Seite 1von 7

PREMIER TECHNOLOGY GROUP

Test Paper [ C & C++ ] NO. OF QUESTIONS : 25


Duration : 30 MIN.

INSTRUCTIONS :

 Do not write anything on the question paper.


 Each question carries 1 mark.
 Wrong answers carries 0.25 Negative mark.

1. What will be output of the following program?


class MyClass
{
public :
static int count;
public :
void Incr_Count ( void ){ count++; }
void Show_Count ( void ){ cout << count; }
};

void main ( void )


{
MyClass obj1, obj2;
obj2.count = 100;
obj1.Incr_Count ( );
obj1.Show_Count ( );
}

1) Will give compilation error


2) will give linker error
3) 101
4) 100

2. What will be output of the following program?


class MyClass
{
int x, y;
public :
void Set ( int m, int n = 0 ){ x = m; y = n; }
void Set ( int m ){ x = m; y = 100; }
void Show ( void ){ cout << “x= “ << x++ << “y= “ << y++; }
};
void main ( void )
{
MyClass obj1;
obj1.Set ( 100 );
obj1.Show ( );
}
1) x = 100 y = 100
2) x = 101 y = 101
3) x = 100 y = 1
4) Will give compilation error

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.
PREMIER TECHNOLOGY GROUP

3. What will be output of the following program?


class MyClass
{
int val;
public :
void Show ( void ) { cout << val; }
void Set_Val ( int X ) { val = X; }
};
MyClass *fun ( MyClass myClass )
{
MyClass *pMyClass = &myClass;
pMyClass->Set_Val ( 10 );
pMyClass->Show ( );
return pMyClass;
};
void main ( void )
{
MyClass obj1, *ptr;
obj1.Set_Val ( 1 );
obj1.Show ( );
ptr = fun ( obj1 );
obj1.Show ( );
ptr->Show ( );
}
1) 110110
2) 1101010
3) 11011
4) can not say

4.
------------------------- is a class of which one can not create objects.

5.
------------------ is a member function of a class which gets automatically executed when instance of a class gets
destroyed.

6.
Is it possible to overload operator == so that it compare two char[] using a string comparison?
1. Yes
2. No

7. From the following list what are operators which can’t be overloaded?
I. ()
II. [ ]
III. sizeof
IV. ::
1) III & I
2) III & II
3) III & IV
4) All

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.
PREMIER TECHNOLOGY GROUP

8. What will be output of the following program?


class MyClass
{
int val;
public :
void Set ( void ) { val = 100; }
void Show ( void ) { cout << val++; }
};
void main ( void )
{
MyClass * const pMyClass = new MyClass;
pMyClass->Set ( );
pMyClass->Show ( );
}

1) 100
2) 101
3) compilation error
4) None of these

9. When destructor should be virtual?


1) When you may delete a derived object via a derived pointer.
2) When you may delete a derived object via a base pointer.
3) When you may delete a base object via a derived pointer.
4) There is no such virtual destructor in C++.

10. What will be output of the following program?


class MyClass
{
int val;
public :
MyClass ( ) { val = 100; }
void Show ( void )const { cout << val; }
void fun ( )const
{
MyClass *pMyClass = ( MyClass * )this;
pMyClass->val = 10;
}
};

void main ( void )


{
const MyClass obj;
obj.fun ( );
obj.Show ( );
}

1) 100
2) 10
3) data of constant object can not be changed.
4) None of these

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.
PREMIER TECHNOLOGY GROUP
11. What will be output of the following program?
class MyBaseClass
{
public :
int val;
.......
};
class MyDerivedClass : MyBaseClass
{ .......
};

In above written code :


1) Base class variable val will be publicly inherited in derived class MyDerivedClass
2) Base class variable val will be privately inherited in derived class MyDerivedClass
3) Base class variable val will be protectedly inherited in derived class MyDerivedClass
4) Base class variable val will not get inherited in derived class MyDerivedClass

12. What will be output of the following program?


class MyClass2; // Forward declaration
class MyClass1
{
public :
void MyFunc ( MyClass2 &obj1 );
};
class MyClass2
{
…………???
};
In above code, If one wants member function MyFunc of class MyClass1 to be friend of class MyClass2, then
how it should be declared in MyClass2?

13. Can friend functions be overloaded ?


1) No
2) Yes

14. What is the difference between keyword struct and keyword class?

15. Can destructor be overloaded?


1) No
2) Yes

16. What will be output of the following program?


class MyBaseClass
{
public :
virtual void Function ( void ) { cout << "In Base"; }
};
class MyDerivedClass : MyBaseClass
{
public :
void Function ( void ) { cout << "In Derived"; }
};
void main ( void )
{
MyDerivedClass *ptr;
MyBaseClass obj;
ptr = ( MyDerivedClass *)&obj;
ptr->Function ( );
}

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.
PREMIER TECHNOLOGY GROUP
1) Will give compilation error.
2) In derived.
3) In base.
4) Will compile with warning on typecasting and will give output as In base class.

17. What is wrong with following code ?


class string
{
public :
string ( const char value = 0 );
~string ( ) {}
};
void f ( )
{
string *ptr = new string [ 100 ];
……
……
delete ptr;
}

18. In the following code, when will the function return the value 1?
int MyFunc ( char ch )
{
int nVal = 0;
if ( ch == 0x80 )
nVal++;
return nVal;
}

19. Which statement is correct ?


I. Friends function has a “this” pointer.
II. Static function has no “this” pointer.
III. Objects created on the heap can’t have “this” pointer.
IV. Virtual function has no “this” pointer.

1) I 2) II 3) III 4) IV

20. What will be output of the following program?


class MyBaseClass
{
public :
void Function ( void ) = 0;
virtual void Display ( void ) { cout << "In Base" ;}
};
class MyDerivedClass : MyBaseClass
{
public :
void Function ( void ) { cout << "Hello "; }
void Display ( void ) { cout << "In Derived" ;}
};
void main ( void )
{
MyDerivedClass *ptr = new MyDerivedClass;
ptr->Function ( );
ptr->Display ( );
}
1) Hello In Derived
2) Hello In Base
3) Compilation error

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.
PREMIER TECHNOLOGY GROUP
4) None of these

21. What will be the output of the following program?


class String
{
char str [ 100 ];
public :
String ( ) { strcpy ( str, "Hi there" ); }
String ( char *ptr ) { strcpy ( str, ptr ); }
String& operator + ( String obj )
{
strcat ( str, obj.str );
return *this;
}
void Display ( void ) { cout << str; }
};
void main ( void )
{
String obj ( "Hello " );
String obj1 ( "World" );
String obj2;
obj2 = obj1 + obj;
obj2.Display ( );
}

1) WorldHello
2) Hi There
3) Hello World
4) None of these

22.
#define MULTIPLY ( A, B ) A* B
int i, j;
i = j = 2;
printf ( “%d”, MULTIPLY ( i + 1, j + 1 ) );

The output from the above code,


1) 4 2) 9 3) 6 4) 5

23. What are pure virtual functions?


24. What will be output of the following program?
class MyClass
{
public :
virtual void Display ( ) { cout << "In Parent"; }
};
class MyChild1 : public MyClass
{
public :
void Display ( ) { cout << "In Child1"; }
};
class MyChild2 : public MyClass
{
public :
void Display ( ) { cout << "In Child2"; }
};

class MyGrandChild : public MyChild1, public MyChild2


{
};

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.
PREMIER TECHNOLOGY GROUP
void main ( void )
{
MyGrandChild *ptr = new MyGrandChild;
ptr->Display ( );
}

1) In Parent
2) In Child1
3) In Child2
4) Compilation error

25. What is the data type of NULL in C?


1) int 2) pointer to int 3) pointer to void 4) pointer to float

148, Thaper Enclave, Ramdaspeth, Nagpur – 440010. Tel.: 91-712-546179, 546734 Fax: 555820.
Email : admin@premiertechnologygroup.com
Proprietary and confidential – DO NOT COPY – © 2000 PTGPL.

Das könnte Ihnen auch gefallen