Which output of the following program is empty?

the following is the program source code:

class base{
    private:
        int x;
    public:
        void setx(int a) {x = a;}
        int getx() {return x;}
};

int main(){
    int * p;
    base a;
    a.setx(55);
    p = new int(a.getx());
    cout << *p;
}
CPP
Feb.28,2021

are you sure you compiled it? cout < < * p; you didn't even add a semicolon. In addition, have you added -sharpinclude < iostream > and using namepspace std; ? And CPP's main must be return an integer, not void .

I have tested the following code and output 55.

-sharpinclude <iostream>

using namespace std;

class base {
    private:
        int x;
    public:
        void setx(int a) {x = a;}
        int getx() {return x;}
};

int main() {
    int * p;
    base a;
    a.setx(55);
    p = new int(a.getx());
    cout << *p;
    return 0;
}
Menu