Arizona State University (ASU) CSE100 Principles of Programming with C++ Midterm 1 Practice Exam

Question: 1 / 400

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

create

new

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.

Get further explanation with Examzify DeepDiveBeta

init

allocate

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy