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.

Manipulators:

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, %w.pf in C. The default is right justified

int x=10, y=1000;

cout<

 

 


Related Discussions:- Memory management operator

I want packet capture analysis, I want Packet capture analysis Project D...

I want Packet capture analysis Project Description: Need assistance in debugging some packet capture Skills required is C Programming

Develop activation tool for unattend reseal.xml, Project Description: We...

Project Description: We refurbish older computer and send them back into the market with windows 7 operating system. We are presently using windows deployment services through P

Microprocessor programming, I need to program a microprocessor that would h...

I need to program a microprocessor that would have a temperature, gas, humidity and PIR sensor connected to it. It would send the data to a PC via a Zigbee and receive commands fro

Padovan string, write a program that counts the number of occurrences of th...

write a program that counts the number of occurrences of the string in the n-th Padovan string P(n)   program in java // aakash , suraj , prem sasi kumar kamaraj college

Explain brief about class and objects, Question 1 Write a program that acc...

Question 1 Write a program that accepts a 3x3 matrix from the user and finds the transpose of it Question 2 Explain Brief about class and objects. Also describe friend functi

Random searching, write aprogram for random -search to implement if a[i]=x;...

write aprogram for random -search to implement if a[i]=x;then terminate other wise continue the search by picking new randon inex into a

3n+1, Consider the following algorithm to generate a sequence of numbers. S...

Consider the following algorithm to generate a sequence of numbers. Start with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this process wi

Write a program of inline function, Here is a program that uses an inline f...

Here is a program that uses an inline function to compute and return the absolute value of its input argument. # include inline int abs(int x) {                  ret

C language, There is a pebble merchant. He sells the pebbles, that are used...

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Write Your Message!

Captcha
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