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...
C# programming Create a class called A with private integer field x, protected integer field y,...
C# programming Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f. Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1? Create a method...
C# programming Create a class called A with private integer field x, protected integer field y,...
C# programming Create a class called A with private integer field x, protected integer field y, public integer field z. Create a class B derived from class A with public integer field d and protected integer field e and private field f. Write a main (in a THIRD class called Program) that create an object B and assign all publicly accessible fields of the object with value of 1. Which fields will have a value of 1? Create a method...
[x, y, and z are integer variables, which expressions are equivalent to each other?] a. (x==y...
[x, y, and z are integer variables, which expressions are equivalent to each other?] a. (x==y && x !=z) || (x!=y && x==z) b. (x==y || x==z) && (x!=y || x!=z) c. (x==y) != (x==z)
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.
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...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from...
Using C++ Use dynamic allocation and functions (using pointer variables only) to read the names from the .txt file and sort the names in lexical order Grumpy Dopey Doc Happy Bashful Sneezy Sleepy
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT