Question

Create an integer variable call r and an integer pointer variable called ptr. Now use pointer...

Create an integer variable call r and an integer pointer variable called ptr. Now use pointer logic/code to print the value of r using the pointer variable ptr.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
/*
an integer variable call r
and an integer pointer variable called ptr.
Now use pointer logic/code to print the value of r
using the pointer variable ptr.
*/
//This is c++ code
int main()
{
   int r = 10;
   int *ptr;
   //assign address of r to ptr
   ptr = &r;
   cout << "The value of ptr -> " << *ptr << endl;
   //to hold the output screen
   system("pause");
   return 0;
}

//output

#include<stdio.h>
#include<stdlib.h>
/*
an integer variable call r
and an integer pointer variable called ptr.
Now use pointer logic/code to print the value of r
using the pointer variable ptr.
*/
//This is c code
int main()
{
   int r = 10;
   int *ptr;
   //assign address of r to ptr
   ptr = &r;
   printf("The value of ptr -> %d\n", *ptr);
   //to hold the output screen
   system("pause");
   return 0;
}

//output

//if you need any help regarding this solution ............. please leave a comment .............. thanks

Add a comment
Know the answer?
Add Answer to:
Create an integer variable call r and an integer pointer variable called ptr. Now use pointer...
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
  • Question 17 2 pts A pointer is: A keyword used to create variables A variable that...

    Question 17 2 pts A pointer is: A keyword used to create variables A variable that stores address of an instruction A variable that stores address of other variable A macro defined as a preprocessor directive. 2 pts Question 18 The operator used to get value at address stored in a pointer variable is: O& && O II Question 19 2 pts In the following code what is 'P: typedef char *charp; const charp P; Pis a constant Pis a...

  • TRUE/FALSE 1. If pl is an integer pointer variable, with the value of 1000, pl++ changes...

    TRUE/FALSE 1. If pl is an integer pointer variable, with the value of 1000, pl++ changes P1 to point to the memory location 1001. ANSWER: T 2. When you return a dynamic array to the freestore, you must include the number of elements in the array 3. You can assign an array to a pointer variable. 4. The size of dynamic arrays must be declared at compile time. 5. int *pl; declares a static variable. ANSWER: F ANSWER: F ANSWER:...

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

  • C++ only : Use an integer pointer returning function which would determine the sum of square...

    C++ only : Use an integer pointer returning function which would determine the sum of square of each of two integer pointer variables used as argument of the function. Call the function in the main() using pointer variables and dynamic allocation Question 4: Print both the strings using string double-pointer only in the main() void print(string ** s){ **s = "University of Oregon"; cout<< **s <<endl; } void print(string *x){ *x = "Portland"; cout<<*x<<endl; }

  • Create a typedef called timeType and a struct called timeType_struct with 3 components: an integer hr,...

    Create a typedef called timeType and a struct called timeType_struct with 3 components: an integer hr, an integer min, and an integer sec Create a typedef called tourType and a struct called tourType struct with 3 components: a 50 character city name, an integer distance, and a travel time of type timeType. Write a void function that takes a pointer parameter to a tourType struct as input and prints it. Write a value-returning function that prompts for all the data...

  • Create a #define called MAPSIZE. Set to 10. Create global variables DirectionsFilename and MapFilename. Use char...

    Create a #define called MAPSIZE. Set to 10. Create global variables DirectionsFilename and MapFilename. Use char arrays and set them to nulls by using {}. Create a structure called RowCol that has two int members called row and col to hold the row and column. Function MoveNorth should have a return value of void and a parameter of a pointer to RowCol. { To move north, you need to subtract 1 from PositionPtr->row. Before doing so, you need to check...

  • Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to...

    Code should be in C# Create a class called SavingsAccount.  Use a static variable called annualInterestRate to store the annual interest rate for all account holders.  Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance.  Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....

  • 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: Creates an integer variable AND an integer pointer variable Ask the user to input an integer value Store the value in the integer variable Print the address of the variable. Make the pointer variable point at the integer value Print the value pointed to by the pointer Print the address of the pointer

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point...

    C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...

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