Question 1
Question
Inline functions are useful when
Answer
-
Function is large with many nested loops
-
Function has many static variables
-
Function is small and we want to avoid function call overhead.
-
none of the above
Question 2
Question
#include<iostream>
using namespace std;
int x = 1;
void fun()
{
int x = 2;
{
int x = 3;
cout << ::x << endl;
}
}
int main()
{
fun();
return 0;
}
Question 3
Question
Predict the output of following C++ program
#include<iostream>
using namespace std;
union A {
int a;
unsigned int b;
A() { a = 10; }
unsigned int getb() {return b;}
};
int main()
{
A obj;
cout << obj.getb();
return 0;
}
Question 4
Question
Which of the following is true about inline functions and macros.
Answer
-
Inline functions do type checking for parameters, macros don't
-
Macros are processed by pre-processor and inline functions are processed in later stages of compilation.
-
Macros cannot have return statement, inline functions can.
-
Macros are prone to bugs and errors, inline functions are not
-
all of the above
Question 5
Question
How can we make a C++ class such that objects of it can only be created using new operator? If user tries to create an object directly, the program produces compiler error.
Answer
-
Not possible
-
By making destructor private
-
By making constructor private
-
By making both constructor and destructor private
Question 6
Question
Would destructor be called, if yes, then due to which vector?
#include <iostream>
#include <vector>
using namespace std;
class a
{
public :
~a()
{
cout << "destroy";
}
};
int main()
{
vector <a*> *v1 = new vector<a*>;
vector <a> *v2 = new vector<a>;
return 0;
}
Answer
-
v1
-
v2
-
v1&v2
-
no destructor call
Question 7
Question
#include<iostream>
using namespace std;
int x[100];
int main()
{
cout << x[99] << endl;
}
Answer
-
0
-
99
-
run time error
-
unpredictable
Question 8
Question
#include<iostream>
using namespace std;
int main ()
{
int cin;
cin >> cin;
cout << "cin" << cin;
return 0;
}
Question 9
Question
A member function can always access the data in __________ , (in C++)
Answer
-
the class of which it is member
-
the object of which it is a member
-
the public part of its class
-
the private part of its class
Question 10
Question
Which of the following is not correct for virtual function in C++ ?
Answer
-
Virtual function can be static.
-
Must be declared in public section of class.
-
Virtual function should be accessed using pointers.
-
Virtual function is defined in base class.
Question 11
Question
Which of the following is not correct (in C++) ?
1.Class templates and function templates are instantiated in the same way
2.Class templates differ from function templates in the way they are initiated
3.Class template is initiated by defining an object using the template argument
4.Class templates are generally used for storage classes
Question 12
Question
In C++, polymorphism requires:
Question 13
Question
Method over-riding can be prevented by using final as a modifier at ______
Answer
-
the start of the method declaration in the derived class.
-
the start of method declaration.
-
the start of derived class.
-
the start of the class.
Question 14
Question
In C, what is the effect of a negative number in a field width specifier?
Answer
-
the values are displayed right justified
-
the values are displayed centered
-
the values are displayed left justified
-
the values are displayed as negative numbers