MEMORY MANAGEMENT OPERATOR IN C ++ PROGRAMMING

Memory Management Operator in C ++ Programming


Dynamic Memory Allocation


When we declare any variable in a C ++ program, the compiler and the operating system allocate space for our variables in memory before the program is executed, and the memory allocated is automatically deleted when the program is finished. ,


But if we want it to be in our control at all, that is, when the program is running, then the compiler allocates space for us, then we have to use the new and delete operators in C ++ programming. This method is also called Dynamic Memory Allocation.


In C ++, two Unary Operators and new delete are used to do memory dynamically (dynamic) management during execution. New and Delete Operators are used to replacing memory and eliminate variables from memory, respectively.


Memory Management Operator


New Operator


Variables or objects can be created in runtime using New. Using New we can build a data type object and a user-defined data type object. Its Syntax is as follows.


Syntax :- variable_name = new DataType;


Example :-


a = new int;

b = new float;


Here a and b are two variables that are created by the new operator. So when our program is executed, memory will be allocated for a and b only.


Delete Operator


We use this to remove data items from memory. By the way, even if we do not use the delete operator, all the variables and objects are deleted from memory.


Syntax :- delete variable_name


Example:


delete a, b;


AKASH TIMES

I AM AN ENGINEER BY PROFESSION BUT BLOGGER IS MY OLD DAYS DREAM TO CREATE MY OWN SITE FOR THOSE WHO ARE CURIOUS ABOUT MY BIRTHPLACE THEN I AM COMING FROM (INDIA). THE CURRENT CITY LIVES IN NAVI MUMBAI, INDIA

Post a Comment

IF YOU HAVE ANY PROBLEM PLEASE FELL FREE TO CONTACT US BY - AKASH TIMES

PREVIOUS POST NEXT POST