Dynamic Integer Allocation

#include <iostream>
using namespace std;

int main() {
    int x;
    cin >> x;

    // Dynamically allocate memory for a single integer
    int* ptr = new int;

    // Store the input value in allocated memory
    *ptr = x;

    // Print the value stored in dynamic memory
    cout << *ptr;

    // Free the allocated memory
    delete ptr;

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

42

Expected Output

42