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.
Which of the following statements is true?
- A constant member function does allow changes to any data members in the class
- A static member functions allows access to non-static data
- The size of the object is the sum of size of all non-static data
- The size of a struct variable is the sum of size of all static and all non-static
data
Answer to Question 1
What is the output of the following?
#include
void main()
{
int x = 20;
int &t = x;
x = 50;
cout << x << " "
<< t;
}
- 20 50
- 50 20
- 50 50
- None of the above
Answer to Question 2
Friend function adds flexibility to the language, but they are controversial
- Because it goes against the rule of data encapsulation
- Because it can access a class's private data
- Both A and B
- None of the above
Answer to Question 3
Which of the following is true about a destructor?
- Destructor like a constructor can accept arguments
- Destructor can be overloaded
- Destructor function is the same name as a class which is preceded by the tilde
character
- Destructor return type is void
Answer to Question 4
The prototype of output operator in the class "test" is as follows
- friend ostream & operator << (ostream &, test &)
- ostream & operator << (ostream &, test &)
- friend ostream & operator << (test &)
- friend ostream & operator << (ostream &)
Answer to Question 5
Which of the following statements is false?
- Friend functions take one argument more than a member function
- Operator overloading allows us to create new operators
- Static member functions can access only static data
- A constant cannot be changed
Answer to Question 6
Which of the following statements is true?
- We cannot overload operator new and operator delete
- Each instance of a class has a different copy of static data
- We need to define in every class a constructor and destructor
- class istream extends class ios
Answer to Question 7
What is the output of the following?
#include <iostream.h>
int add(int, int = 5, int = 10);
void main() {
cout << add(10) << "
" << add(10, 20) << " " << add(10, 20, 30);
}
int add(int a, int b, int c)
{
return a + b + c;
}
- compilation error
- 25 40 60
- 15 30 60
- 20 40 60
Answer to Question 8
To turn overloading off, which of the statements is used?
- extern "C"
- static "C"
- Register "C"
- off "C"
Answer to Question 9
The keywords related to exception handling are?
- test, catch
- try, throw, catch
- namespace, catch
- try, finally
Answer to Question 10
Genericity is a technique to
- Defining software components that have more than one interpretation depending
on the data type of parameter.
- Which allows the extension of the functionality of the existing software components.
- To derive a class from more than one base class.
- Of creating new data types that are well suited to an application.
Answer to Question 11
Comments are
- Integral part of the program and they do nothing
- Integral part of the program and they help in coding and maintenance
- Are not part of the program
- Are not part of the program and they slow down the execution speed
Answer to Question 12
C++ does not support the following feature?
- Multiple inheritance
- Polymorphism
- Operator overloading
- Automatic memory management
Answer to Question 13
What is the output of the program?
#include <iostream.h>
char *buf1 = "Genesis", *buf2 = "InSoft";
void main()
{
char* const q=buf1;
*q='x';
cout << *q;
}
- x
- xenesis
- l-value specifies constant object
- None of the above
Answer to Question 14
What happens when new operator is called?
- It invokes operator new, then invokes the constructor and then does type casting
- It invokes the constructor, calls operator new and then does type casting
- It invokes operator new and then invokes the constructor
- It invokes the constructor and then does type casting
Answer to Question 15
Which keyword violates data encapsulation?
- Public
- Virtual
- Friend
- Protected
Answer to Question 16
Which of the following is not true about destructor?
- Destructor can be overloaded
- A destructor class member function is typically used to return dynamically allocated
memory
- A destructor function has the same name as the class in which it is defined preceded
by the tilde character
- A destructor does not have any return type
Answer to Question 17
What is the output of the program?
#include <iostream.h>
void main()
{
int val = 5;
int &val1 = val;
int &val2;
cout << val1;
}
- 5
- val2 - references must be initialized
- Address of variable val is printed
- None of the above
Answer to Question 18
What happens when delete operator is called?
- It invokes operator delete and then invokes the destructor if any
- It invokes the destructor if any and then calls operator delete
- It invokes operator delete
- It invokes the destructor if any
Answer to Question 19
Which of the following are true about default arguments?
- Default arguments must be the last argument
- A default argument cannot be redefined in later declarations even if the redefinition
is identical to the original
- Additional default arguments can be added by later declarations
- All of the above
Answer to Question 20
Answers
Answer 1 - C
Back to question 1
Answer 2 - C
Back to question 2
Answer 3 - C
Back to question 3
Answer 4 - C
Back to question 4
Answer 5 - A
Back to question 5
Answer 6 - B
Back to question 6
Answer 7 - D
Back to question 7
Answer 8 - B
Back to question 8
Answer 9 - A
Back to question 9
Answer 10 - B
Back to question 10
Answer 11 - A
Back to question 11
Answer 12 - B
Back to question 12
Answer 13 - D
Back to question 13
Answer 14 - A
Back to question 14
Answer 15 - A
Back to question 15
Answer 16 - C
Back to question 16
Answer 17 - A
Back to question 17
Answer 18 - B
Back to question 18
Answer 19 - A
Back to question 19
Answer 20 - D
Back to question 20