Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Q1) Create an structure and demonstrate the use of dynamic memory allocation.
- #include <iostream>
- #include<stdlib.h>
- using namespace std;
- struct dynamic{
- string statement;
- int size;
- };
- int main(){
- dynamic* object=(dynamic*)malloc(sizeof(dynamic));
- object->statement="Dynamically allocated memory of size: ";
- object->size=sizeof(dynamic);
- cout<<object->statement<<" "<<object->size<<endl;
- free(object);
- object=NULL;
- cout<<"Memory released!!!"<<endl;
- return 0;
- }
- /*
- OUTPUT:
- Dynamically allocated memory of size: 40
- Memory released!!!
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement