C Help 62 Pointer Assignment For this part of the lab lab3b

C++ Help!!!

6.2.   Pointer Assignment

For this part of the lab (lab3b), these are the requirements:
•   Declare a normal integer variable called numIcedTea and initialize it to 10
•   Declare an integer pointer called ptrIcedTea
•   Set the integer pointer to point at the numIcedTea memory address
•   Print the variable value of ptrIcedTea
•   Print the dereferenced value of ptrIcedTea
•   Using ptrIcedTea update the value to 20
•   Print the updated value of numIcedTea
•   Print the dereferenced value of ptrIcedTea
Here is an example of the code running.
-bash-4.1$ ./lab3b
ptrIcedTea = 0x7ffec030d894
*ptrIcedTea = 10
numIcedTea = 20
*ptrIcedTea = 20
-bash-4.1$

Solution

#include <iostream>
using namespace std;
int main()
{
   int numIcedTea;
   numIcedTea=10;//step1
   int *ptrIcedTea;//step2
   ptrIcedTea=&numIcedTea;//step3
   cout << ptrIcedTea << endl ;//step4
   cout << *ptrIcedTea << endl ;//step5
   *ptrIcedTea=20;//step6
   cout << numIcedTea << endl ;//step7
   cout << *ptrIcedTea << endl ;//step8
   return 0;
}

C++ Help!!! 6.2. Pointer Assignment For this part of the lab (lab3b), these are the requirements: • Declare a normal integer variable called numIcedTea and init

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site