Thursday, July 29, 2010
C Question Set 1-2
Question 1
What does an empty class contain?
Default constructor
Copy constructor
Address of operator
All of the above
Question 2
In protected derivation
Protected and public members of base class become protected
Private, protected and public members of base class become protected
Private, protected and public members of base class become private
Protected and public members of base class become private
Question 3
What is the output of the program?
#include <iostream.h>
void main()
{
int j = 20, k = 30;
int & m = j;
int * n = &j;
cout << j << " " << k << " " << m << " ++ " ;
m = k;
cout << j << " " << k << " " << m << " ++ ";
n = &k; // n now points to k
cout << j << " " << k << " " << m << " " << *n << endl;
}
20 30 20 ++ 20 30 30 ++ 30 30 30 30
20 30 20 ++ 30 30 30 ++ 20 30 30 30
20 30 20 ++ 20 30 30 ++ 20 30 30 30
20 30 20 ++ 30 30 30 ++ 30 30 30 30
Question 4
Class istream in iostream.h is defined as
Class istream : public ios
Class istream : public virtual ios
Class istream : public iostream
Class istream : public virtual iostream
Question 5
Interface contains
At least one pure virtual function
No pure virtual function
All pure virtual functions
None of the above
Question 6
What is the size of empty class?
0 bytes
2 bytes
1 byte
4 bytes
Question 7
The advantage of defining a pure virtual member function in a class is
Derived class may implement the pure virtual function
Derived class must implement the pure virtual function
Derive class is abstract class if it does not implement the pure virtual function
Both B and C
Question 8
What is the output of the following?
#include
void main()
{
int x, y;
x=(3, 4, 5);
y=3, 4, 5;
cout << endl << x <<" "<< y;
}
Compilation Error
3 5
3 3
5 3
Question 9
What is the output of the following?
#include <iostream.h>
void main ()
{
{
for(int x=1; x <= 5; x++, x+=5);
}
cout << endl << " value of x = " << x;
}
6
7
compilation error
2
Question 10
What is the output of the following?
#include <iostream.h>
void main ()
{
cout << (cout<<" Hello ") << " world ";
}
No output is displayed
Hello some_address_value world
Hello world
compilation error
Question 11
The class fstreambuf serves as base class for
ifstream, ofstream, fstream
ifstream, ofstream
ostream
ifstream
Question 12
The scope resolution operator permits
Access to an identifier in the global scope that has been hidden by another identifier with the same name in the local scope
Access to an identifier in the global space
Access to an identifier in the local scope
Access to an identifier in the local scope and global scope
Question 13
The declaration
void func_name( )
accepts
Any no of arguments
Only one argument
No Arguments
None of the above
Question 14
The technique of allocating memory during runtime on demand is known as
Dynamic binding
Dynamic memory allocation
Late binding
Template
Question 15
What is the output of the following?
#include
void main()
{
enum col {red, blue, yellow};
col c = blue << 1;
cout << c;
}
1
2
3
4
Question 16
The advantage of defining a pure virtual member function in a class is
Derived class may implement the pure virtual function
Derived class must implement the pure virtual function
Derive class is abstract class if it does not implement the pure virtual function
Both B and C
Question 17
Input and output operators are known as
extraction and insertion
get from and put to
Both A and B
None of the above
Question 18
A file can be tied to your program by defining an instance of
fstream
ifstream
ofstream
All of the above
Question 19
Which of the following is not true about constructor
constructor can be overloaded
constructor return type is int
constructor has the same name as the class in which it is defined
constructor are used for initializing data members
Question 20
What is the output of the program?
#include <iostream.h>
char *buf1 = "Genesis", *buf2 = "InSoft";
void main()
{
const char *p = buf1;
p = buf2;
*p = 'g';
cout << *p;
}
What is the output of the program?
g
genesis
No ouput is displayed
l-value specifies constant object
Answers
Answer 1 - D
Answer 2 - A
Answer 3 - D
Answer 4 - B
Answer 5 - C
Answer 6 - C
Answer 7 - D
Answer 8 - D
Answer 9 - C
Answer 10 - B
Answer 11 - A
Answer 12 - A
Answer 13 - C
Answer 14 - C
Answer 15 - B
Answer 16 - D
Answer 17 - C
Answer 18 - D
Answer 19 - B
Answer 20 - D
======================================================================
C++ Question Bank 03 / FAQs [20 QUESTIONS]
Question 1
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
Question 2
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
Question 3
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
Question 4
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
Question 5
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 &)
Question 6
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
Question 7
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
Question 8
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
Question 9
To turn overloading off, which of the statements is used?
extern "C"
static "C"
Register "C"
off "C"
Question 10
The keywords related to exception handling are?
test, catch
try, throw, catch
namespace, catch
try, finally
Question 11
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.
Question 12
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
Question 13
C++ does not support the following feature?
Multiple inheritance
Polymorphism
Operator overloading
Automatic memory management
Question 14
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
Question 15
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
Question 16
Which keyword violates data encapsulation?
Public
Virtual
Friend
Protected
Question 17
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
Question 18
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
Question 19
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
Question 20
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
Answers
Answer 1 - C
Answer 2 - C
Answer 3 - C
Answer 4 - C
Answer 5 - A
Answer 6 - B
Answer 7 - D
Answer 8 - B
Answer 9 - A
Answer 10 - B
Answer 11 - A
Answer 12 - B
Answer 13 - D
Answer 14 - A
Answer 15 - A
Answer 16 - C
Answer 17 - A
Answer 18 - B
Answer 19 - A
Answer 20 - D
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment