c++ delete int

#include <iostream>

int main() {
    int* ptr = new int;  // Step 1: Dynamically allocate memory for an integer.

    *ptr = 42;           // Step 2: Assign a value to the dynamically allocated integer.

    std::cout << "Value before deletion: " << *ptr << std::endl;  // Step 3: Display the value before deletion.

    delete ptr;          // Step 4: Deallocate the dynamically allocated memory.

    // Accessing *ptr after deletion leads to undefined behavior.

    return 0;
}