Home » C++ Quiz Questions

C++ | new and delete operators | question 1

What is the correct syntax to declare an integer variable dynamically in C++ programming language?

(1) int *ival = new int(10);

(2) int ival = new int (10);

(3) Both (1) and (2)

(4) None of these

Answer: (1)

Explanation:

new is an operator in C++ programming language that is used to declare memory dynamically. Here, in this question we are going to allocate memory for an integer variable dynamically.

To declare memory at dynamic, the declaration syntax is:

    data_type *pointer_name = new data_type([value]);

Here, [value] is optional, we can also assign it later (after the declaration)

Therefore, correct declaration statement will be: int *ival = new int(10);



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.