What keyword is used to create a new object in C++?

Prepare for the ASU CSE100 Programming Exam with C++ Study Guide. Review flashcards, multiple choice questions, with hints and explanations. Master your exam!

In C++, the keyword used to create a new object is "new." When you use "new," it dynamically allocates memory for an object on the heap and returns a pointer to that memory. This is essential in scenarios where you need objects that outlive the scope in which they were created or when you don't know the number of objects you will need at compile time.

Using "new" allows for the creation of complex data structures and the management of memory, which is crucial in many programming situations. For example, writing MyClass* obj = new MyClass(); creates an instance of MyClass and returns a pointer to it, enabling you to use that object throughout its lifetime until it is explicitly deallocated with "delete."

Other options like "create," "init," and "allocate" are not keywords in C++. They may represent concepts related to object creation or memory management, but they do not function as reserved words in the C++ language used for creating objects. While you may encounter similar terms in other contexts or programming languages, only "new" has the specific functionality required in C++ for dynamic object creation.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy