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
  • 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...

  • Make one program using Dev c++, and explain how program works Final Program Requirements: Declare an...

    Make one program using Dev c++, and explain how program works Final Program Requirements: Declare an int variable and int array with four elements in the main program. Initial values for the intvariable and int array are hardcoded in the program. Declare an int pointer in the main program.Program shows the values of the integer variable and integer arrayelements. Program shows the addresses of the variable and each integer array element. Store addresses inpointers temporarily prior to displaying. The addresses...

  • Hello, I have my piece of C programming code and I have a pointer initialized to...

    Hello, I have my piece of C programming code and I have a pointer initialized to point to my array and I need help to display the contents of my array using a while loop or do-while loop. The stop condition should be when the pointer reaches '\0'. The code is below: #include <stdio.h> int main () {    char array[80]; printf("Enter a string: "); scanf("%[^\n]", &array); printf("%s\n", array); char * p;    p = array;         }

  • Python help! I need help getting my code to increment the value. It keep calculating the...

    Python help! I need help getting my code to increment the value. It keep calculating the range over the same number and not moving up! this is the question Write a program named q1() that prompts the user for the starting and ending distance in Kilometers (km), and an increment value. It should then print the conversion table showing values for Kilometers, Miles (M) and Feet (ft). Each value should be displayed as they are calculated. and this is the...

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
ADVERTISEMENT