Initialization Allocating Memory In C++
Whenever
we want a variable to dynamic memory allocated so we have to use new keyword
for that time or if we want to new keyword through allocated memory to destroy so we have to use
delete keyword. Like that we can do memory initialization or deletion.
Fig: Initialization Allocating Memory In C++
Syntax:
data
type *variable name=NULL;
variable
name=new data type;
*variable
name=value;
Example:
int
*a=NULL;
a=new
int;
*a=20;
Program:
#include<iostream.h>
#include<conio.h>
void
main()
{
int
*a=NULL;
a=new
int;
*a=20;
cout<<”example
of initialization allocated memory”;
cout<<a;
delete
a;
getch();
}
Output:
Example
of initialization allocated memory 0x8f910dc6
No comments:
Post a Comment