Question

Write a C++ program to do the following: Declare and assign values to int variables x,...

Write a C++ program to do the following:

  1. Declare and assign values to int variables x, y
  2. Declare an int variable z; and store the sum of x and y in it
  3. Declare a pointer called pz and point it in the heap direction (using new)
  4. Store the z value in the heap location using the pz pointer
  5. Print the content of the pz pointer
  6. Print the pointer (the address)

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int main() {
    // Declare and assign values to int variables x, y
    int x = 5, y = 7;
    // Declare an int variable z; and store the sum of x and y in it
    int z = x + y;
    // Declare a pointer called pz and point it in the heap direction (using new)
    int *pz = new int;
    // Store the z value in the heap location using the pz pointer
    *pz = z;
    // Print the content of the pz pointer
    cout << *pz << endl;
    // Print the pointer (the address)
    cout << pz << endl;
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Declare two int: x and y Declare two pointers p and q capable of pointing to...
Declare two int: x and y Declare two pointers p and q capable of pointing to int Make p point to y Make q point to x Assign 3 and 6 to x and y without mentioning x and y Redirect p to point to the same location q points to (two ways) Make q point to y Swap the values of x and y without mentioning x and y. Please write your code in C
Write spim program and execute it on mars. Your program reads two integer values x and...
Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y...
In this lab, we want to get some practice with pointers -- specifically, the basic syntax...
In this lab, we want to get some practice with pointers -- specifically, the basic syntax of declaring them, storing memory addresses into them, dereferencing them, and seeing how they work with pointer arithmetic in the context of built-in, C-style arrays. Unless specified otherwise, you can use any valid variable names you wish. The requirements for this program are as follows: Part A Declare a pointer-to-int, initialized to nullptr. Declare an int variable, initialized to some value of your choice....
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
float sum( float x, float y, float z ) ​program in c++
Here are the function prototypes for your homeworkWrite out the actual functions themselves Also, create a main function that demonstrates that all four functions work The user should be able to provide four values to your program (three floats and an int) Your program should then use your four new functions and also display the results to the user NONE of these functions should print values themselvesfloat sum( float x, float y, float z ); // returns the sum of three floatsfloat mean( float...
Program: 6: Function overloading AIM: To write a C++ program to illustrate the concept of function...
Program: 6: Function overloading AIM: To write a C++ program to illustrate the concept of function overloading. PSEUDOCODE: Declare necessary variables. Create a class with add(int,int) ,add(float,float) as member functions and necessary variable. add(int,int) is used to add two integer values. add(float,float) is used to add two float values. Using object call the required function with corresponding input. Display the output.
Write a C++ program to perform the following tasks     a) Declare an integer array of...
Write a C++ program to perform the following tasks     a) Declare an integer array of size 1000.     b) Initialize the array with random values between 1 and 9.     c) Write the code to find and print, how many 1’s occur in the array.
5) Write a java program with scanner object to input first number and second number as...
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement. Steps: 1) Declare scanner object 2) Ask system out print for first number and declare variable first number 3) Ask system out print for second number and declare variable second number 4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and...
write a c++ program A class called car (as shown in the class diagram) contains: o...
write a c++ program A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be  Incremented whenever a new Car object is created.  Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars....
Write a C function to compute the following output (int) based on two input (int) variables:...
Write a C function to compute the following output (int) based on two input (int) variables: output = a*a + b*b - 2*a*b If the value of output is '0', then return -1 instead. Call the C function 4 times from main() with values of 'a' and 'b' as follows and print output values for each case. a = 3, b = 4 a = 1, b = 1 a = -2 b = 3 a = -4 b =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT