Question

In: Computer Science

1) Dynamic Allocation (c++) a. Create two integer variables x and y, initialize them with different...

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

Solutions

Expert Solution

#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


Related Solutions

Write a program (main.cpp) to test the following: 1) Static allocation a. Create two integer variables...
Write a program (main.cpp) to test the following: 1) Static allocation a. Create two integer variables x and y, initialize them with different values. b. Use static 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 2) Dynamic allocation...
Question 1 Consider the following two Diophantine equations with integer variables X and Y (1) 99...
Question 1 Consider the following two Diophantine equations with integer variables X and Y (1) 99 X + 225 Y = 36 (2) 225 X + 99 Y = 33 (a) Determine which of these two equations is inconsistent, and explain why (you can use the Maple commands ifactor and/or gcd ). For the equation that is consistent, apply Extended Euclid's Algorithm to find a solution  {X0, Y0} . (b) Find now all solutions  {X, Y} of that equation, and identify the...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting from 1. Your element [0][0] should be equal to 1; element[4][4] should be equal 25. Print the array. The output should have 5 rows and 5 columns. Specify the width for each output to demonstrate the table in a formatted view. Change the value of the elements: 2nd row 4th column to 24, 1st row 3rd column to 13. Print the array again. Find...
You have a function taking in two integer variables, x and y. You want to subtract...
You have a function taking in two integer variables, x and y. You want to subtract x from y, but you want to make sure the result does not overflow. Write some lines of code (assuming x and y are already defined integers with values in them) to check if the result would be an overflow if x was subtracted from y. Do this without allowing an overflow to happen.
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable...
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use this pointer variable to initialize the myNums array from 2 to 200 and then display the array elements. Delete the dynamic array myNums at the end. You just need to write part of the program.
Assume that your two variables, X and Y, are integrated of different orders, explain step by...
Assume that your two variables, X and Y, are integrated of different orders, explain step by step how you will: Q.4.2 Test for cointegration and the chosen method?    
Let X and Y be two independent random variables such that X + Y has the...
Let X and Y be two independent random variables such that X + Y has the same density as X. What is Y?
x, y, z, w, u and t are integer variables, what will their value be after...
x, y, z, w, u and t are integer variables, what will their value be after the execution of the statements below. Give the final value of each variable x = 7; y = x + 1; z = x % (y – 2) + 4; y = (y + z ) % (x + 4) ; w = (x * y) / (z – 3); x = x + x; u = w - 3; t = z +...
Provide an example that if the cov(X,Y) = 0, the two random variables, X and Y,...
Provide an example that if the cov(X,Y) = 0, the two random variables, X and Y, are not necessarily independent. Would you please give the example specifically and why?
Provide an example that if the cov(X,Y) = 0, the two random variables, X and Y,...
Provide an example that if the cov(X,Y) = 0, the two random variables, X and Y, are not necessarily independent. Would you please give the example specifically and why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT