C++ Program that will fill whole memory


In this article we will see how to fill the whole memory by writing a simple C++ program. Here the logic is very simple. We shall create new integer variables by using the dynamic memory allocation. If we create some variables again and again, it will fill the entire primary memory.

In C++ to dynamically allocate a memory space we can use the new keyword.

The basic syntax of the new operator is like below.

pointer_var = new data_type

To deallocate the memory space, we can use the delete keyword. The syntax is

delete pointer_var

Note After running this program it may slow down the performance of the system. The total system may not work properly due to the lack of memory space.

Example Code

#include<iostream>
using namespace std;
main() {
   while(true) {
      int *var = new int; //allocate memory dynamically
   }
}

Output

Here we cannot get any specific output to display. We can check the
memory status in the task manager to get the idea about the output.

Updated on: 30-Jul-2019

208 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements