Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Filename: c_array_mem_allocation_test.cpp
- // Version: 1.0.0
- // Author: Jeoi Reqi
- /*
- DESCRIPTION:
- This C++ program demonstrates dynamic memory allocation by prompting the user to input the size of an array,
- creating an array of that size dynamically, filling it with random integers, and then deallocating the memory.
- Author: [Author's Name]
- Date: [Date of Creation]
- REQUIRED LIBRARIES:
- - iostream: For input and output operations.
- USAGE:
- - Compile and run the program.
- - Input the size of the array when prompted.
- - The program will generate random integers and output them.
- */
- #include <iostream>
- using namespace std;
- int main() {
- int size;
- cout << "Enter the size of the array (1-1000): ";
- cin >> size;
- int* ptr = new int;
- int* arr = new int[size];
- for (int i = 0; i < size; i++) {
- arr[i] = rand() % 1000;
- cout << arr[i] << " ";
- }
- delete ptr;
- delete[] arr;
- return 0; // Return 0 to indicate successful program execution
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement