Thursday, July 29, 2010
C Question Set 1-3
Question 1
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
Question 2
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
Question 3
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
Question 4
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
Question 5
What is the prototype of pre increment operator in class test?
void operator ++ ();
test operator ++ (int);
void operator ++ (int);
test operator ++ ();
Question 6
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
Question 7
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
Question 8
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
Question 9
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 &);
Question 10
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
Question 11
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
Question 12
The only member functions that could be called for const objects would be?
Constructors
Destructor
Const member functions
All of the above
Question 13
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
Question 14
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
Question 15
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
Question 16
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
Question 17
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
Question 18
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
Question 19
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
Question 20
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
Answers
Answer 1 - D
Answer 2 - B
Answer 3 - C
Answer 4 - B
Answer 5 - D
Answer 6 - D
Answer 7 - C
Answer 8 - A
Answer 9 - D
Answer 10 - C
Answer 11 - A
Answer 12 - D
Answer 13 - D
Answer 14 - A
Answer 15 - D
Answer 16 - D
Answer 17 - C
Answer 18 - D
Answer 19 - C
Answer 20 - D
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment