What are the constructors and destructors in C++?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What are the constructors and destructors in C++??

๐Ÿต๐ŸŒผ๐Ÿ’๐ŸŒธ๐Ÿ’ฎ๐Ÿต๐Ÿ’๐ŸŒธ๐ŸŒผ

15th Apr 2019, 7:52 AM
Nithya Yamasinghe
Nithya Yamasinghe - avatar
3 Answers
+ 7
Constructors allocate memory for objects and initialize them. Destructors free the memory and other resources.
15th Apr 2019, 11:15 PM
Sonic
Sonic - avatar
+ 4
Constructors do not allocate memory for objects (that's done with 'new'). They are used to initialize an object (instance of a class) with an valid state.
16th Apr 2019, 12:04 PM
Daniel Adam
Daniel Adam - avatar