Question discussion

What is the output of the following C++ program?#include using namespace std; struct T { T() { cout

1585Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
using namespace std;
struct T {
    T() { cout << "c"; }
    T(const T&) { cout << "k"; }
    ~T() { cout << "d"; }
};
void f(T t) {}
int main() { T a; f(a); }
  • Ackdd
  • Bckd
  • Ccdd
  • Dcckd
Correct answer: A

Explanation

a is constructed (c), the by-value parameter is copy-constructed (k) and destroyed when f returns (d), and finally a is destroyed (d).

Discussion 0

Nobody has replied yet. Start the discussion!