Question

Hello. I just need help with my c++ code. Write a program that: Creates an integer...

Hello. I just need help with my c++ code.

Write a program that:

  1. Creates an integer variable AND an integer pointer variable
  2. Ask the user to input an integer value
  3. Store the value in the integer variable
  4. Print the address of the variable.
  5. Make the pointer variable point at the integer value
  6. Print the value pointed to by the pointer
  7. Print the address of the pointer
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main()
{
    // Creates an integer variable AND an integer pointer variable
    int i;
    int* p;
    
    // Ask the user to input an integer value
    cout<<"Enter an integer: ";
    
    // Store the value in the integer variable
    cin>>i;
    
    // Print the address of the variable.
    cout<<"the address of the variable is "<<(&i)<<endl;
    
    // Make the pointer variable point at the integer value
    p = &i;
    
    // Print the value pointed to by the pointer
    cout<<"the value pointed to by the pointer is "<<(*p)<<endl;
    
    // Print the address of the pointer
    cout<<"the address of the pointer is "<<p<<endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Hello. I just need help with my c++ code. Write a program that: Creates an integer...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am writing C++ code, and I need help for this. Create a program that will...

    I am writing C++ code, and I need help for this. Create a program that will convert a decimal value into Roman numeral, and output the result. The program will ask for an integer input, assume all inputs are valid, and the program should not end unless the user tells you to. C++ code.

  • I need help getting my program to reject a negative input from the user. Here is...

    I need help getting my program to reject a negative input from the user. Here is what I have: #short description of what the program will do print("Hello, this program will ask you to enter a non-negative decimal integer. The program will then show the binary equivalent of the integer you choose.") #ask the user to enter the non-negative decimal integer number= int(input("Enter a non-negative decimal integer: ")) while number< 0: print("Number Cannot Be Negative!! Try again...") #create a variable...

  • please write the code in C++ AND BE VERY SURE OF IT SINCE IT IS AN...

    please write the code in C++ AND BE VERY SURE OF IT SINCE IT IS AN ASSIGNMENT WITH LOTS OF MARKS - DON'T COPY FROM THE INTERNET I- For each of the following, write a single statement that performs the specified task. Assume that long integer variables value1 and value2 have been declared and value1 has been initialized to 200000. a)- Declare the variable longPtr to be a pointer to an object of type long. b)- Assign the address of...

  • Please code in c 1. Write a program which does the following: Declare and initialize three...

    Please code in c 1. Write a program which does the following: Declare and initialize three pointers. One points to an integer, one points to a float and one points to a character variable Ask the user to enter appropriate values for these variables. Output the values to the screen by accessing the variables directly and then by using pointer references. Print the address of each variable. Modify the variables by performing any arithmetic operation only using pointer refer- ences...

  • I need help with the C++ for the following problem: Write a program that can store...

    I need help with the C++ for the following problem: Write a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following: 1. Calculate the sum and average of the array. 2. Output the content (value) that stored in the array of five elements. 3. Continue to ask the user to store for storing data into another array.

  • Write C++ code that creates an integer variable called number. Dereference a given pointer gPointer and...

    Write C++ code that creates an integer variable called number. Dereference a given pointer gPointer and places that value into the variable number. The pointer gPointer will have been declared and set to point to a value before your code runs. Your code will be placed inside the main function with all the appropriate #includes. After your code runs, the test case will execute the following code: cout << "number = " << number << endl; For example: Test Result...

  • Pointer tasks: ( In C++ ) 1. Write a program to store the address of a...

    Pointer tasks: ( In C++ ) 1. Write a program to store the address of a character variable and a float variable. • Print the address of both variables. • Print the values of variable using dereference operator. • Add 2 in float value using pointer. • Print address of character variable using reference operator. 2. Write a program that takes 5 elements in an array and print them in reverse order using pointers. 3. Write to program that takes...

  • I need help writing a C programming code. I am trying to create a program that...

    I need help writing a C programming code. I am trying to create a program that returns ANY given number's decimal value as an Integer (Whole number). Examples: User input: 0.35 Output: 35 User input: 1.465 Output: 465 User input: 10.6054 Output: 6054

  • hello please i need help ASAP QUICKLY Write down a complete C++ program that will use...

    hello please i need help ASAP QUICKLY Write down a complete C++ program that will use the following functions related with a triangle; a) a function that will let the user to input the and to return the sizes of the three sides, let say a, b, c. b) a function that will calculate and return the area of the triangle; Area=(1/2)(a+b+c) c) a function that will print the sizes of the triangle and its area on the screen. Then...

  • Hello, I need help with my assignment; write a c program that reads a bunch of...

    Hello, I need help with my assignment; write a c program that reads a bunch of characters from the keyboard from 'a' through 'z', space, newline and linefeed characters ( using get char), and Keep counts each of the letters 'a' through 'z'.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT