2 What is the output produced when the following code iscompiled and executed? #
ID: 3613281 • Letter: 2
Question
2 What is the output produced when the following code iscompiled
and executed?
#include <iostream>
using namespace std; //introduces namespace std
int main()
{
int *p1, *p2, x=3;
p1 = new int;
*p1 = x * 20;
p2 = p1;
cout << "A: " << x * *p1 << " " << *p2<< endl;
*p2 = 30;
cout << "B: " << x * *p1 << " " << *p2<< endl;
p1 = new int;
*p1 = 40;
cout << "C: " << x * *p1 << " " << *p2<< endl;
return 0;
}
2
a) A: 180 60
B: 30 90
C: 120 30
b) A: 180 60
B: 90 30
C: 30 120
c) A: 180 60
B: 90 30
C: 120 30
d) No output will be generated because the code will notcompile
e) No output will be generated because the code will cause the
program to end abnormally.
Explanation / Answer
please rate - thanks 2 What is the output produced when the following code iscompiled and executed? #include using namespace std; //introduces namespace std int main() { int *p1, *p2, x=3; p1 = new int; *p1 = x *20; //*p1=3*20=60 p2 =p1; //p2=p1 coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.