Please Write a c++ program that introduces int variables x and y and int* pointe
ID: 3776138 • Letter: P
Question
Please Write a c++ program that introduces int variables x and y and int* pointer variables p and q. Set x to 2, y to 8, p to the address of x, and q to the address of y. Then print the following information:
(a) The address of x and the value of x. (1 pt)
(b) The value of p and the value of *p. (1 pt)
(c) The address of y and the value of y. (1 pt)
(d) The value of q and the value of *q. (1 pt)
(e) The address of p (not its contents!). (1 pt)
(f) The address of q (not its contents!). (1 pt)
try to use simple language please
Thank you!!
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
//declare variables x and y
int x, y;
//declare pointer variables p and q of type int
int *p,*q;
//assign the address of the variables x and y using address operator & preciding variable name
p = &x;
q = &y;
//Assign 2 to x and 8 to y
x =2;
y = 8;
//print the required info using print library function
printf("The address of x=%u and the value of x = %d ",&x,x);
printf("The value of p =%u and the value of *p = %d ",p,*p);
printf("The address of y = %u and the value of y = %d ",&y,y);
printf("The value of q = %u and the value of *q = %d ",q,*q);
printf("The address of p = %u ",&p);
printf("The address of q = %u ",&q);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.