Create the following C++ Code: a. (1 point) Declare and assign values to variabl
ID: 3876497 • Letter: C
Question
Create the following C++ Code:
a. (1 point) Declare and assign values to variables i. Declare an integer variable called myInt and assign the value 15 to it. ii. Declare a pointer variable called myPointer using the kreieremce operaior (*) and assign ii io the nemory location of myInt using the address-of operator (&) b. (1 point) Print to console i. Print the memory location of myInt (remember the address-of operator!) and the value of myPointer. ii. Print the value of myInt and the value pointed to by myPointer (remember the dereference operator!) c. (1 point) Change values and print to console i. Change the value of myInt to 10 ii. Print the memory location of myInt (remember the address-of operator!) and the value of myPointer. ii. Print the value of myInt and the value pointed to by myPointer (remember the dereference operator!)Explanation / Answer
#include <iostream>
using namespace std;
int main ()
{
//a.
// declaring variables:
int myInt;
int * myPointer;
// Assign the values:
myInt = 15;
myPointer = &myInt; // myPointer = address of myInt
//b.
// print out the "address-of operator" result:
cout << "memory location of myInt is " << &myInt << ' ';
cout << "value of myPointer is " << myPointer << ' ';
// print out the "dereference operator" result:
cout << "value of myInt is " << myInt << ' ';
cout << "value pointed to by " << *myPointer << ' ';
//c.
// Change the value:
myInt = 10;
// print out the "address-of operator" result:
cout << "memory location of myInt is " << &myInt << ' ';
cout << "value of myPointer is " << myPointer << ' ';
// print out the "dereference operator" result:
cout << "value of myInt is " << myInt << ' ';
cout << "value pointed to by " << *myPointer << ' ';
// terminate the program:
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.