C++ Exam answers 3
C++ Exam answers 3
C++ Exam answers 3
1. void main()
{
int friend;
friend+=5;
}
The above code is
a) C valid only.
b) C and C++ valid.
c) C++ valid only.
d) C and C++ invalid
2. int a;
void main()
{
int a;
a=50;
::a=20;
cout << a;
}
The above piece of code will print:
a) The value of 20.
b) Compiler will give an error.
c) The Value of 50.
d) None of above.
1/7
ITI C++ Exam
d) No, there must be no arguments without defaults to the right of the default
arguments.
4. void main()
{
int *p;
p=new int(5);
}
The above code
a) Allocates an integer that is not initialized.
b) Allocates an array of integers of 5 elements that is not initialized.
c) Allocates an integer that is initialized by 5.
d) Allocates an array of integers where all its elements is initialized by 5.
5. class myclass
{
int x;
protected:
int y;
};
void main()
{
myclass c1;
c1.x=100;
c1.y=500;
2/7
ITI C++ Exam
}
The above code will produce
a) An error, x is private.
b) An error, y is protected.
c) No error
d) Both (a) and (b)
7. Which type of stand alone functions is allowed to access the private members of a
class?.
a) Template Function.
b) Inline Function.
c) Friend Function.
d) Overloaded Function.
8. class base
{
int x;
protected:
int y;
public:
int c;
};
class derived:private base
{
//some code
};
Class derived can access:
a) Private and protected members of base class.
3/7
ITI C++ Exam
9. class base
{
public:
base(){cout << "Constructing base class\n";}
};
class derived:public base
{
public:
derived(){cout << "Constructing derived class\n";}
};
void main()
{
derived d;
}
The following code will print:
a) Constructing base class
b) Constructing base class
Constructing derived class
c) Constructing derived class
d) Constructing derived class
Constructing base class
4/7
ITI C++ Exam
{
public:
void say() {cout << "\n I’m derived \n";}
};
void main()
{
base *pb;
base mybase;
derived myderived;
pb=&mybase;
pb->say();
pb=&myderived;
pb->say();
}
Calss ThreeD {}
Void myfunc (ThreeD & t);
a) The destructor not to be called
a) The constructor not to be called
5/7
ITI C++ Exam
6/7
ITI C++ Exam
18. Aggregation is
a) A special type of inheritance
b) A special type of association
c) Is similar to association
d) Is similar to inheritance
زى كدة
Clas Rectangle {
Public:
Rectangle(Point * p1 , Point * p2);
}
يعىن البوينرتز بتبقى ىف جانب واحد أو ىف كالس واحد ىف حالة األسوسياشن
a) One pointer in the one side
b) Set of pointers in the one side
c) One pointer in the either sides.
d) Set of pointer in the either sides.
7/7