Interview Questions

C++ Questions only (2)

C++ programming on UNIX, C++ Networking,C++ Algorithm Questions and Answers


(Continued from previous question...)

C++ Questions only (2)


10.
int count=0;
class obj
{
public: obj(){
count++;
}
~obj() {
count--;
}
};

main()
{
obj A,B,C,D ;
return 0 ;
}

What is the value of "count" immediately before
the return statement above is executed?
1) 0
2) 1
3) 2
4) 3
5) 4


11.
class Foo;

What is the above sample code an example of?
1) A class constructor
2) A class object instantiation
3) A class definition
4) A class declaration
5) A syntax error


12.
1: class Foo {
2: int size; string name; double value;
3:
4: public:
5: Foo() : size(0), name("unknown"), value(0.0) {
6: }
7: Foo(int s) {
8: size = s; name = "unknown"; value = 0.0;
9: }
10: Foo(int s = 0, string n = "unknown", double v=0) {
11: size = s; name = n; value = v;
12: }
13: };

Referring to the sample code above, on which one of
the following lines does an initializer list occur?
1) Line 2
2) Line 5
3) Line 8
4) Line 10
5) Line 11


13.
Scenario:-
Your manager has asked you to integrate an existing project
with an external timer. Her requirements include adding a global
variable whose contents can be only read by the software
but whose value will be continuously updated by the hardware clock.

Referring to the above scenario, which one of the following
variable declarations satisfies all the requirements?
1) extern volatile clock;
2) extern const volatile long clock;
3) extern long clock;
4) extern const mutable long clock;
5) extern mutable long clock;


14.
Giving the following class definitions, how many subobjects of class V in class X?
class V { /* ... */ };
class B1 : virtual public V { /* ... */ };
class B2 : virtual public V { /* ... */ };
class B3 : public V { /* ... */ };
class X : public B1, public B2, public B3 { /* ... */};


15.
class Foo {
int i;
public:
Foo(int x) : i(x) { }
};

1: Foo *f = new Foo;
2: Foo &f = new Foo(1);
3: int i = Foo::i;
4: Foo *af = new Foo[10];
5: const Foo &af = Foo(1);

Referring to the sample code above, which one
of the numbered lines of code is legal C++?
1) Line 1
2) Line 2
3) Line 3
4) Line 4
5) Line 5


16.
Which set of preprocessor directives is used
to prevent multiple inclusions of header files?
1 #ifndef, #define and #endif
2 #ifdefined and #enddefine
3 #define and #endif only
4 #$if and #endif
5 #if and #define


17.
Which one of the following statements is TRUE
in regard to overloading the ++ operator?
1 You cannot define a post-increment operator.
2 You cannot define a pre-increment operator
3 You cannot define both a pre-increment
and post increment operator for a class.
4 You must use a dummy parameter to
define a post increment operator.
5 You should always create a pre-increment
operator when overloading ++.

(Continued on next question...)

Other Interview Questions