+ 1

What is output of this code?

class MyClass{ private: int *data; int siz; public: MyClass(int sz) { this->siz=sz; data=new int[sz]; for(int i=0;i<sz;i++) data[i]=i+2; } int get_end() { return data[this->data[siz]]; } ~MyClass() { delete data; } }; int main() { MyClass a(4); MyClass b=a; cout<<b.get_end(); return 0; }

8th Mar 2020, 11:45 AM
QT Develop
QT Develop - avatar
4 Réponses
+ 3
Why don't you try in Code Playground, what the output is?
8th Mar 2020, 12:06 PM
HonFu
HonFu - avatar
+ 1
Thats it
8th Mar 2020, 12:09 PM
QT Develop
QT Develop - avatar
+ 1
It's just a memory leak.
8th Mar 2020, 2:46 PM
QT Develop
QT Develop - avatar