Problem: Answer the following questions first, then write a program to verify yo
ID: 3682439 • Letter: P
Question
Problem: Answer the following questions first, then write a program to verify your results (Hint: after each statement, add a cout statement).Submit this page and your program together.
A C++ program contains the following statements:
float a,*pa;
float b, *pb;
float c;
a = 3.0;
b = 1.9;
pa = &a;
*pa = 3*a;
pb = &b;
*pb += 0.5;
c = *pa +*pb;
Suppose each floating-point number occupies 4 bytes of memory. Assume further that the address of variable a is 128800, the address of variable b is 128804, and the address of variable c is 128808.
Draw a layout of memory, its variables and its pointers. Then answer the following questions.
ii) What value is assigned to pa?_______________________
ii) What value is represented by *(&a)? ________________________
iii) What value is represented by *pa? __________________________
iv) What value is represented by &(*pb)? _______________________
v) What value is assigned to c? ____________________________
vi) What value is assigned to pb? ___________________________
Explanation / Answer
#include <iostream>
using namespace std;
int main(void) {
// your code goes here
float a,*pa;
float b, *pb;
float c;
a = 3.0;
b = 1.9;
pa = &a;
*pa = 3*a;
pb = &b;
*pb += 0.5;
c = *pa +*pb;
cout<< pa << endl;
cout<< *(&a) << endl;
cout<< *pa << endl;
cout<< &(*pb) << endl;
cout<< c << endl;
cout<< pb << endl;
return 0;
}
output
Success time: 0 memory: 3456 signal:0
i) 0xbf859fec(128800)
ii) 9
iii) 9
iv) 0xbf859fe8(128804)
v) 11.4
vi) 0xbf859fe8((128804)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.