TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Tuesday 16 June 2020

Dynamic Memory Allocation In C++| Dynamic Memory Allocation In C++ Programming Language | Dynamic Memory Allocation In C++ In Hindi

Dynamic Memory Allocation In C++


When we use any kind of static memory allocation at that time we not define size so error came on our program in display so we have to solve that problem we use dynamic allocation operator.

Using  of dynamic allocation operator we can use the size of memory so that time  we can increase or decrease so the means of dynamic is run time  so its is known as run time memory allocation.

In which 2 type operator are used, and they are given:

     1.   New

     2.   Delete

image of dynamic memory allocation in c++

Fig: Dynamic memory allocation  


1.New

  For Program execution time use variable for memory allocated to use new operator.

New is a type of keyword.


Syntax:

pointer variable = new  datatype [size];


  Example:

*p=new int[10];


Program:

#include<iostream.h>

#include<conio.h>

void main

{

int  *p;

p=new int[15];

*p=13;

cout<<”&p=”<<&p;

cout<<”*p=”<<*p;

getch();

}

Output:

*p=13&p=0*8f94fff4*p=13

 

2.Delete

This is one type keyword. For new keyword through allocated memory to destroy  to do work on it.


Syntax:

delete pointer variable;


Example:

delete p;


Program:

#include<iostream.h>

#include<conio.h>

void main

{

int  *p;

p=new int[15];

*p=13;

cout<<”&p=”<<&p;

getch();

}


Output:

&p=0x8f92fff4


No comments:

Post a Comment