Back-End Programming Exam  >  Back-End Programming Tests  >  Test: Constructor And Destructor - 1 - Back-End Programming MCQ

Test: Constructor And Destructor - 1 - Back-End Programming MCQ


Test Description

10 Questions MCQ Test - Test: Constructor And Destructor - 1

Test: Constructor And Destructor - 1 for Back-End Programming 2024 is part of Back-End Programming preparation. The Test: Constructor And Destructor - 1 questions and answers have been prepared according to the Back-End Programming exam syllabus.The Test: Constructor And Destructor - 1 MCQs are made for Back-End Programming 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Constructor And Destructor - 1 below.
Solutions of Test: Constructor And Destructor - 1 questions in English are available as part of our course for Back-End Programming & Test: Constructor And Destructor - 1 solutions in Hindi for Back-End Programming course. Download more important topics, notes, lectures and mock test series for Back-End Programming Exam by signing up for free. Attempt Test: Constructor And Destructor - 1 | 10 questions in 20 minutes | Mock test for Back-End Programming preparation | Free important questions MCQ to study for Back-End Programming Exam | Download free PDF with solutions
Test: Constructor And Destructor - 1 - Question 1

A ………………….. is used to declare and initialize an object from another object.

Test: Constructor And Destructor - 1 - Question 2

Output?
#include<iostream>
#include<string.h>
using namespace std;
 
class String
{
    char *str;
public:
     String(const char *s);
     void change(int index, char c) { str[index] = c; }
     char *get() { return str; }
};
 
String::String(const char *s)
{
    int l = strlen(s);
    str = new char[l+1];
    strcpy(str, s);
}
 
int main()
{
   String s1("geeksQuiz");
   String s2 = s1;
   s1.change(0, 'G');
   cout << s1.get() << " ";
   cout << s2.get();
}

Detailed Solution for Test: Constructor And Destructor - 1 - Question 2

Since there is no copy constructor, the compiler creates a copy constructor. The compiler created copy constructor does shallow copy in line " String s2 = s1;" So str pointers of both s1 and s2 point to the same location. There must be a user defined copy constructor in classes with pointers ot dynamic memory allocation.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Constructor And Destructor - 1 - Question 3

Destructor is a member function whose name is same as the class name but is preceded by a ………..

Test: Constructor And Destructor - 1 - Question 4

We must use initializer list in a constructor when

Test: Constructor And Destructor - 1 - Question 5

Whenever const objects try to invoke non-const member functions, the compiler …………………

Test: Constructor And Destructor - 1 - Question 6

#include<iostream>
using namespace std;
  
class Test
{
public:
  Test();
};
  
Test::Test()  {
    cout << " Constructor Called. ";
}
  
void fun() {
  static Test t1;
}
  
int main() {
    cout << " Before fun() called. ";
    fun();
    fun();
    cout << " After fun() called. ";  
    return 0;
}

Detailed Solution for Test: Constructor And Destructor - 1 - Question 6

Note that t is static in fun(), so constructor is called only once.

Test: Constructor And Destructor - 1 - Question 7

The process of initializing through a copy constructor is known as ……………

Test: Constructor And Destructor - 1 - Question 8

#include<iostream>
using namespace std;
 
class Test
{
public:
   Test(Test &t) { }
   Test()        { }
};
 
Test fun()
{
    cout << "fun() Calledn";
    Test t;
    return t;
}
 
int main()
{
    Test t1;
    Test t2 = fun();
    return 0;
}

Test: Constructor And Destructor - 1 - Question 9

An ………………….. with a constructor or destructor cannot be used as a member or a union.

Test: Constructor And Destructor - 1 - Question 10

Constructors have _____ return type.

Detailed Solution for Test: Constructor And Destructor - 1 - Question 10

Constructors have no return type

Information about Test: Constructor And Destructor - 1 Page
In this test you can find the Exam questions for Test: Constructor And Destructor - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Constructor And Destructor - 1, EduRev gives you an ample number of Online tests for practice
Download as PDF