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

Please write in C++! Thank you (3 pts) In your main function, create a variable

ID: 3887914 • Letter: P

Question

Please write in C++! Thank you

(3 pts) In your main function, create a variable x that holds an integer (any integer you want). Print out the address of x in the main. Now write a function that is called by pointer with an integer. Pass in the variable x’s address. In the function print out the value at the address, the address in the parameter, and the address of the parameter.

(3 pts)In your main function, create a variable y that holds an integer (again, pick an integer). Print out the value in y and the address of y. Now, using call by reference, write a function with an input parameter. Print out the address and the value of the input parameter.

Explanation / Answer

#include<iostream>
using namespace std;
void func(int *x){
//print value at address of x
printf("value at address :%d ",*x);
//print Address in x
printf("Address in parameter:%d ",x);
//print Address of x
printf("Address of the parameter :%d ",&x);
}
//call by reference or Address
void callbyref(int *y){
//print value at Address y
printf("ref Y value:%d ",*y);
//pritn address y
printf("ref y address:%d ",y);
}
int main(){
int x = 10;
int y = 20;
printf("Address of variable :%d ",&x);
//pass Address of x to func
func(&x);
printf("Y value:%d ",y);
printf("Y address:%d ",&y);
//pass address of y to callbyref
callbyref(&y);
return 0;
}

/* sample output
Address of variable :1818923164
value at address :10
Address in parameter:1818923164
Address of the parameter :1818923128
Y value:20
Y address:1818923160
ref Y value:20
ref y address:1818923160
*/