Memory management operator, C/C++ Programming

Assignment Help:

Memory Management Operator

In C malloc( ), calloc( ), realloc( ), and free( ) are used to mange dynamic memory.  In

addition to these function C++ have derived two unary operators new and delete to perform dynamic allocation of memory.   An object or variable may be created or destroyed by using these functions.  The syntax for to create a dynamic memory allocation is

pointer_variable = new data_type;


int *p;

p = new int;

The above two statements can be written in one stroke or line. int *p = new int;

*p = 25; Assigning 25 through pointer


It can also be initialized in one stroke or line. The syntax to initialize the new operator is:

pointer_variable = new data_type (value);

int *p = new int(25);


The new operator can also be used in array

int *pa = new int[10];  This will create memory space for 10 integers the first element is

referred as p[0].....p[9];


When using multi dimension arrays all the array sizes must be specified, the first array may be variable the remaining must be constants.

pm = new int[N][3][3];

To release the memory the syntax is delete pointer_variable;

delete p; will release the memory stored by the pointer variable p. delete [ ]pa; will release dynamically allocated array.


The most widely used manipulators are endl and setw.


cout <<"This is C++ program"<< endl; The endl work just like "\n"


The setw operator is used to specify the width of the output.  It is similar to %wd, in C. The default is right justified

int x=10, y=1000;




Related Discussions:- Memory management operator

Difference between mutex and binary semaphore, Semaphore is used to synchro...

Semaphore is used to synchronize processes. whereas mutex is used to give synchronization among threads running in the similar process.

Develop a biomedical imaging project, Develop a biomedical imaging project ...

Develop a biomedical imaging project Project Description: This is a biomedical imaging project. Skills required are C++ Programming, Cocoa, Mac OS, Objective C

#superASC2 SRTING COST, A string S is said to be "Super ASCII", if it conta...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Friendly function and rules of friend function, F r i e n dly Function...

F r i e n dly Function: A class can have public members and private members.   The public member can be used through the class using dot operator.   Where as private me

C program to check prime numbers , C Program to check PRIME NUMBERS   ...

C Program to check PRIME NUMBERS   main() {           int i,k,r,flag;           clrscr();           printf("ENTER THE NO. TO CHECK IT IS PRIME OR NOT: ");

Describe difference between malloc()/free() & new/delete?, for object, mall...

for object, malloc allocates memory in heap however doesn't invoke object's constructor to initialize the object. new allocates memory & also invokes constructor to initialize the

Create complex number using constructor , Create Complex number using const...

Create Complex number using constructor: class complex                                 {                                                   private:

Do friends break encapsulation?, A: No. If they're utilized properly, they ...

A: No. If they're utilized properly, they increase encapsulation. You frequently require splitting a class in half while the two halves will have distinct numbers of instances o

I want vlc pitch changing addon, I want VLC Pitch Changing Addon Project...

I want VLC Pitch Changing Addon Project Description: Required: Plugin to modify the pitch of running tracks in VLC without changing the speed. Skills required are C Progra

Write Your Message!

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd