20. Dynamic Integer Allocation

Dynamically allocate a single integer using new.
Assign it a value read from input, print that value, and then free the memory using delete.

Steps required in main():

  1. Read an integer x from input.
  2. Dynamically allocate an int using new.
  3. Store x in the allocated memory.
  4. Print the stored value.
  5. Free the memory using delete.

Important:

  • Do not use stack variables to hold the value (except for reading input).
  • The printed value must come from the dynamically allocated memory.

Example 

Input:

42

Output:

42

Constraints:

  • Use new and delete.
  • Do not use new[] or delete[].

 

 

 

 

Loading...

Input

42

Expected Output

42