Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What are the parts of the literal constants?
Correct Answer is : Output in C is 1 and in C++ is 1
2. How are the constants declared?
Correct Answer is : struct STRUCT S;
3. Which of the following statement is not true about preprocessor directives?
Correct Answer is : 1
4. Regarding the following statement which of the statements is true?
const int a = 100;
Correct Answer is : Error
5. How to declare a wide character in the string literal?
Correct Answer is : 0
6. What is the role of a constructor in classes?
Correct Answer is : cin: garbage value
7. Why constructors are efficient instead of a function init() defined by the user to initialize the data members of an object?
Correct Answer is : Array element access
8. What will be the output of the following C++ code?
#include
#include
using namespace std;
class A{
int a;
public:
A(int i){
a = i;
}
void assign(int i){
a = i;
}
int return_value(){
return a;
}
};
int main(int argc, char const *argv[])
{
A obj;
obj.assign(5);
cout<
Correct Answer is : All members of a class
9. What will be the output of the following C++ code?
#include
#include
using namespace std;
class A{
int a;
A(){
a = 5;
}
public:
void assign(int i){
a = i;
}
int return_value(){
return a;
}
};
int main(int argc, char const *argv[])
{
A obj;
obj.assign(10);
cout<
Correct Answer is : 4 and 1
10. In the following C++ code how many times the string “A’s constructor called” will be printed?
#include
#include
using namespace std;
class A{
int a;
public:
A(){
cout<<"A's constructor called";
}
};
class B{
static A a;
public:
B(){
cout<<"B's constructor called";
}
static A get(){
return a;
}
};
A B::a;
int main(int argc, char const *argv[])
{
B b;
A a1 = b.get();
A a2 = b.get();
A a3 = b.get();
}
Correct Answer is : 1 and 1
11. What happens if a user forgets to define a constructor inside a class?
Correct Answer is : struct is not required in C++ but required in C while declaring an object of the structure
12. How many parameters does a default constructor require?
Correct Answer is : struct cannot have member function in C but it can in C++
13. How constructors are different from other member functions of the class?
Correct Answer is : The program gives an error in case of C but runs perfectly in case of C++
14. How many types of constructors are there in C++?
Correct Answer is : The program gives an error in case of C but runs perfectly in case of C++
15. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"Default constructor called\n";
}
A(const A& a){
cout<<"Copy Constructor called\n";
}
};
int main(int argc, char const *argv[])
{
A obj;
A a1 = obj;
A a2(obj);
}
Correct Answer is : The program gives an error in case of C but runs perfectly in case of C++
16. What is the output of the following C++ code?
#include
#include
using namespace std;
class A{
mutable int a;
public:
A(){
cout<<"A's default constructor called\n";
}
A(const A& a){
cout<<"A's copy Constructor called\n";
}
};
class B{
A obj;
public:
B(){
cout<<"B's Constructor called\n";
}
};
int main(int argc, char const *argv[])
{
B b1;
B b2;
}
Correct Answer is : Structure in C++ allows Constructor definition
17. What is the role of destructors in Classes?
Correct Answer is : The program gives an error in case of C but runs perfectly in case of C++
18. What is syntax of defining a destructor of class A?
Correct Answer is : this pointer is passed as a hidden argument in all non-static functions of a class
19. When destructors are called?
Correct Answer is : ->
20. What is the difference between constructors and destructors?
Correct Answer is : To access the members of a class which have the same name as local variables in that scope