[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C++ Programming :: Functions - Discussion

Home > C++ Programming > Functions > MCQs Questions Discussion

3 / 14

What is the output of the C++ program?

#include <iostream>
using namespace std;
class base {
    int b;
public:
    base (int x) {
        b = x;
        cout << "Base";
    };
};
class derived : public base
{
    double d;
public:
    derived(double x, int y);
    d = x;
    cout << " Derived";
};

int main () {
    derived d(23.5, 10);
}

ADerived

BBase

CBase Derived

DCompilation error: No appropriate base class constructor available

Answer: Option (Login/Signup)

Show Explanation

#include <iostream>

using namespace std;


class base {

    int b;

public:

    base (int x) {

        b = x;

        cout << "Base";

    };

};

class derived : public base

{

    double d;

public:

    derived(double x, int y);

    d = x;

    cout << " Derived";

};


int main () {

    derived d(23.5, 10);

}

Answer: Compiler throws "error: ‘d’ does not name a type" and "error: ‘cout’ does not name a type" errors.

This is because statements in c++ should be inside a function but  d = x; and cout << " Derived"; are defined directly inside a class.

Asked In :: Commvault

Post Your Answer Here:     

Reply    
Rate This: +0 -0
    Report


Report Error

Please Login First Click Here