Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ (Addresses): a.) In main( ), declare 3 ints and set them to the values of 10

ID: 3692053 • Letter: C

Question

C++ (Addresses):
a.) In main( ), declare 3 ints and set them to the values of 10, 20 and 30. Then print out the address of each of these 3 ints. What do you get???
b.) Now add a pointer variable to this main(). Make the pointer point to the first int that you declared in part a. Now print out the pointer and the value of the pointer. What do you get? C++ (Addresses):
a.) In main( ), declare 3 ints and set them to the values of 10, 20 and 30. Then print out the address of each of these 3 ints. What do you get???
b.) Now add a pointer variable to this main(). Make the pointer point to the first int that you declared in part a. Now print out the pointer and the value of the pointer. What do you get? C++ (Addresses):
a.) In main( ), declare 3 ints and set them to the values of 10, 20 and 30. Then print out the address of each of these 3 ints. What do you get???
b.) Now add a pointer variable to this main(). Make the pointer point to the first int that you declared in part a. Now print out the pointer and the value of the pointer. What do you get?

Explanation / Answer

a)

The address of first variable is 0xbfac0714
The address of second variable is 0xbfac0718
The address of third variable is 0xbfac071c

b)

The value in the pointer variable is 0xbfac0714
The value it is pointing to is 10

Code:

#include <iostream>
using namespace std;

int main() {
   // First part
   int a=10,b=20,c=30;
   cout<<"The address of first variable is "<<&a<<endl;
   cout<<"The address of second variable is "<<&b<<endl;
   cout<<"The address of third variable is "<<&c<<endl;
  
  
   //Second part
int *p=&a;
cout<<"The value in the pointer variable is "<<p<<endl;
cout<<"The value it is pointing to is "<<*p<<endl;
   return 0;
}