This is a mock Exam for the C++ programmers. It is created by Genesis InSoft Limited
(admin@genesisinsoft.com) and may be
freely distributed so long as it is unmodified. Please email us if you have any
corrections or comments.
What restrictions apply to reference variables?
- You cannot reference a reference variable (i.e. you cannot take its address)
- You cannot create arrays of references
- References are not allowed on bit fields
- All of the above
Answer to Question 1
What is the output of the program?
#include <iostream.h>
struct Emp
{
int id;
float basic;
float cal_salary();
void show_emp();
};
void main()
{
Emp e1;
e1.basic = 5000.5;
cout << e1.basic <<endl;
}
- 5000
- 5000.5
- Error - as private data cannot be accessed
- None of the above
Answer to Question 2
What is the output of the program?
#include <iostream.h>
class test
{
test()
{
cout <<
"constructor called" ;
}
};
void main()
{
test a();
}
- constructor called
- Error - constructor cannot be private
- no output is displayed
- None of the above
Answer to Question 3
What is the output of the program?
#include <iostream.h>
class test
{
int x;
public:
test(int y)
{
x = y;
}
int getX()
{
int x = 40;
return this->x;
}
};
void main()
{
test a(10);
cout << a.getX();
}
- Compilation error
- 10
- 40
- None of the above
Answer to Question 4
What is the prototype of pre increment operator in class test?
- void operator ++ ();
- test operator ++ (int);
- void operator ++ (int);
- test operator ++ ();
Answer to Question 5
What restrictions apply to extern "C"?
- You can specify extern "C" for only one instance of an overloaded function;
all other instances of an overloaded function have C++ linkage
- You can only declare C functions as 'extern "C"
- You cannot declare a member function with extern "C"
- Both A and C
Answer to Question 6
What is the output of the program?
#include <iostream.h>
void fun(int & a, int b)
{
a += 20;
b += 30;
}
void main()
{
int x = 10, y = 50;
fun(x, y);
cout << x << " "
<< y ;
}
- 30 80
- 10 50
- 30 50
- 10 80
Answer to Question 7
What is the output of the following?
#include <iostream.h>
class test
{
char x;
static char c;
};
void main()
{
test a;
cout << sizeof(a);
}
- 1
- 2
- 4
- None of the above
Answer to Question 8
What is the signature of the output operator for class test?
- friend ostream & operator << (test &);
- ostream & operator << (test &);
- ostream & operator << (ostream &, test &);
- friend ostream & operator << (ostream &, test &);
Answer to Question 9
What is the member function called in the statement "test b = a" shown
below?
void main()
{
test a(10);
test b = a;
}
- Assignment operator
- Constructor
- Copy constructor
- None of the above
Answer to Question 10
A variable that is part of a class, yet is not part of an object of that class,
is called a?
- Static member
- Friend member
- Constant member
- Non-static member
Answer to Question 11
The only member functions that could be called for const objects would be?
- Constructors
- Destructor
- Const member functions
- All of the above
Answer to Question 12
Which of the following type conversions is automatic?
-
Conversion from built-in type to class type
-
Conversion from class type to built-in type
-
Conversion from one class type to another class type
-
None of the above
Answer to Question 13
Which keyword do we use if the data members of the class are to be modified even
when it belongs to a constant object?
- mutable
- static
- const
- friend
Answer to Question 14
Which condition should the conversion function from class type to built-in type
satisfy?
- It must be a class member
- It must not specify a return type
- It must not have any arguments
- All of the above
Answer to Question 15
We prefer initialization to assignment for the following reason?
- Const members can only be initialized
- Reference members can only be initialized
- To improve the efficiency, when a class contains a data member which is an object
of another class
- All of the above
Answer to Question 16
Which keyword specifies that those members are accessible only from member functions
and friends of the class and its derived classes?
- private
- public
- protected
- All of the above
Answer to Question 17
Which of the following statements is correct?
- When preceding the name of a base class, the protected keyword specifies that
the public and protected members of the base class are protected members of the
derived class
- Default access of a base class is private for classes
- Default access of a base class is public for structures
- All of the above
Answer to Question 18
What is the output of the program?
# include <iostream.h>
union test {
int x;
};
class uc : public test
{
int y;
};
main()
{
uc u;
cout << sizeof(u);
}
- 8
- 4
- union cannot be used as base class
- None of the above
Answer to Question 19
Which of the following statements are true about static member functions?
- Cannot make use of this pointer
- Cannot access any non-static data
- Cannot be declared const
- All of the above
Answer to Question 20
Answers
Answer 1 - D
Back to question 1
Answer 2 - B
Back to question 2
Answer 3 - C
Back to question 3
Answer 4 - B
Back to question 4
Answer 5 - D
Back to question 5
Answer 6 - D
Back to question 6
Answer 7 - C
Back to question 7
Answer 8 - A
Back to question 8
Answer 9 - D
Back to question 9
Answer 10 - C
Back to question 10
Answer 11 - A
Back to question 11
Answer 12 - D
Back to question 12
Answer 13 - D
Back to question 13
Answer 14 - A
Back to question 14
Answer 15 - D
Back to question 15
Answer 16 - D
Back to question 16
Answer 17 - C
Back to question 17
Answer 18 - D
Back to question 18
Answer 19 - C
Back to question 19
Answer 20 - D
Back to question 20