ou array records bourly temperature of seven days of week For Declare a two dime
ID: 3810374 • Letter: O
Question
Explanation / Answer
Program:
#include <iostream>
using namespace std;
int main() {
int *p1,*p2,v;
v=24; // Here we are initializing value of v
p1=&v; // Here we are assigning value of v to p1 ( i.e p1=24 )
p2=p1; // Here we are assigning value of 1 to p2 ( i.e p2=24 ) so we can say that p2=&v
cout<<v<<" "<<*p1<<" "<<*p2<<endl; // Here we are printing values of v *p1 & *p2
p1=new int;
*p1=42; // Here we are updating value of *p1 as 42
cout<<v<<" "<<*p1<<" "<<*p2<<endl; // Here we are printing values of v , *p1 & *p2
*p2=*p1; // Here we are updating value of *p2 as value of *p1
cout<<v<<" "<<*p1<<" "<<*p2<<endl; // Here we are printing values of v , *p1 & *p2
v=4+2; // Here we are updating value of v as 6 so it updates value of *p2 also because p2=&v
cout<<v<<" "<<*p1<<" "<<*p2<<endl; // Here we are printing values of v , *p1 & *p2
}
Output:
24 24 24
24 42 24
42 42 42
6 42 6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.