I have a final in c++ on wednseday and I need some help with the following revie
ID: 3583278 • Letter: I
Question
I have a final in c++ on wednseday and I need some help with the following review questions.
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
11) Write a line of code that declares an pointer to a double value
double *ptr; //Declares a pointer to a double.
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.
double x = 5.3;
double *newPtr = &x;
13) Now use your pointer to change the value of x to 15.4
*newPtr = 15.4;
14) If I asked you where in memory x is located— write two ways you might print that out to the console.
cout<<"Address of x is: "<<&x<<endl;
cout<<"Address of x is: "<<newPtr<<endl;
15) If I have int funArray[10], Write two ways we’ve learned access the value at the 5th index of funArray
cout<<"Value at index 5 is: "<<funArray[5]<<endl;
cout<<"Value at index 5 is: "<<*(funArray + 5)<<endl;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.