In: Computer Science
1) Dynamic Allocation (c++)
a. Create two integer variables x and y, initialize them with different values.
b. Use dynamic memory allocation, declare px and py as address of x and y separately.
c. Print out x, y, px, py, &x, &y, *px, *py.
d. Let py = px, and *py = 100
e. Print out x, y, px, py, &x, &y, *px, *py.
g. Print out *px++, x, px
#include<iostream>
using namespace std;
int main(){
int x=10,y=20;
int *px=new int;
int *py=new int;
px=&x;
py=&y;
cout<<x<<" "<<y<<" "<<*px<<" "<<*py<<endl;
py=px;
*py=100;
cout<<x<<" "<<y<<" "<<py<<" "<<&x<<" "<<&y<<" "<<*px<<" "<<*py<<endl;
cout<<*px++<<" "<<x<<" "<<px<<endl;
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME