+ 1
May you explain me new and delete in the code, please?
Dynamic Memory https://code.sololearn.com/ckV36vAWidzA/?ref=app
6 Respuestas
+ 5
lifeismyschool
You want to know the meaning of cout or whole code?
+ 2
lifeismyschool int main()
{
int *p = new int; // request memory
*p = 5; // store value
delete p; // free up the memory
// now p is a dangling pointer
p = new int; // reuse for a new address
*p=20;
cout<<&p<<endl; // address of p
cout<<*&p<<endl; // value (a pointer) at address p
cout<<p<<endl; // value of p (an address)
cout<<**&p<<endl; // value (an int) at a ptr value at the address of p
cout<<*p<<endl; // value at p pointer
return 0;
}
+ 1
Please post your question just once. It won't get more answers when it exists a couple of times. Please delete those duplicate questions. Thank you.
0
lifeismyschool
Be more specific when asking questions or let life teach you!
0
Piyush I want to know whole code with cout descriptions.
0
Friends in fact I want to know about using new, NULL, delete, pointer together.