• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C++ Constructors

Question 11

Given the programming constructs i)assignment  ii)for loops where the loop parameter cannot be changed within the loop  iii)if-then-else  iv)forward  go to v)arbitrary go to  vi)non-recursive procedure call vii)recursive procedure/function call  viii)repeat loop, which constructs will you not include in a programming language such that it should be possible to program the terminates (i.e. halting) function in the same programming language.
  • ii), iii), iv)
  • v), vii), viii)
  • vi), vii), viii)
  • iii), v), viii)

Question 12

Constructors have _____ return type.
  • void
  • char
  • int
  • no

Question 13

What is the right way to declare a copy constructor of a class if the name of the class is MyClass?
  • MyClass (constant MyClass *arg)
  • MyClass (constant MyClass &arg)
  • MyClass (MyClass arg)
  • MyClass (MyClass *arg)

Question 14

Predict output of the following program 

C
#include <stdio.h>
int main()
{
   printf("\new_c_question\b\r");
   printf("geeksforgeeks"); 
   getchar();
   return 0;
}
  • ew_c_question
    geeksforgeeks
     

  • new_c_ques
    geeksforgeeks
     


  • geeksforgeeks
     

  • Depends on terminal configuration

Question 15

Fond out the  time complexity of the program 

int a = 0;  

  for (i = 0; i < N; i++) {

       for (j = N; j > i; j--) {       

              a = a + i + j;      

        }

    }

  • O(N^2)

  • O(N^2)

  • O(2*N)

  • O(NlogN)

Question 16

Which of the followings is/are automatically added to every class, if we do not write our own.
  • Copy Constructor
  • Assignment Operator
  • A constructor without any parameter
  • All of the above

Question 17

Output of following C++ code will be?

C++
#include <iostream>
using namespace std;

class X 
{
public:
    int x;
};

int main()
{
    X a = {10};
    X b = a;
    cout << a.x << " " << b.x;
    return 0;
}
  • Compiler Error

  • 10 followed by Garbage Value

  • 10 10

  • 10 0

Question 18

Output of following program? 
 

C++
#include <iostream>
using namespace std;

class Point {
    Point() { cout << "Constructor called"; }
};

int main()
{
    Point t1;
    return 0;
}
  • Runtime Error

  • None of these

  • Constructor called

  • Compiler Error

Question 19

When a copy constructor may be called?

  • When an object of the class is returned by value.
  • When an object of the class is passed (to a function) by value as an argument.
  • When an object is constructed based on another object of the same class
  • When compiler generates a temporary object.
  • All of the above

Question 20

C
#include<iostream>
using namespace std;
class Point {
public:
    Point() { cout << \"Constructor called\"; }
};

int main()
{
   Point t1, *t2;
   return 0;
}
  • Compiler Error
  • Constructor called
    Constructor called
  • Constructor called

There are 26 questions to complete.

Last Updated :
Take a part in the ongoing discussion