I have a final in c++ on wednseday and I need some help with the following revie
ID: 3583266 • Letter: I
Question
I have a final in c++ on wednseday and I need some help with the following review questions.
Questions 11-14 build upon each other
11) Write a line of code that declares an pointer to a double value
12) Now write a line of code that has your new pointer point to a double variable (call it double x) which has the value of 5.3 inside of it.
13) Now use your pointer to change the value of x to 15.4
14) If I asked you where in memory x is located— write two ways you might print that out to the console.
15) If I have int funArray[10], Write two ways we’ve learned access the value at the 5th index of funArray
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
//declare a variable x that has 5 as its value
int x=5;
//6. Declare an integer pointer
int *ptr;
//7. points the pointer to x
ptr=&x;
//8. change the value of x to 15 using pointer variable
*ptr=15;
//9. print the memory location of x, ptr gives the memory location of x and *ptr give value of x
cout<<" The memory location of x is: "<<ptr;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.