Can anyone explain how he each of the answer and also give me a clear answer for
ID: 3755256 • Letter: C
Question
Can anyone explain how he each of the answer and also give me a clear answer for each questions also . Thanks
P.S I do not have the full program.
#include <iostream>
using namespace std;
int main( )
{ typedef int my_2darray[1][1];
my_2darray b[3][2];
cout<<sizeof(b)<<endl;
cout<<sizeof(b+0)<<endl;
cout<<sizeof(*(b+0))<<endl;
// the next line prints 0012FF4C
cout<<"The address of b is: "<<b<<endl;
cout<<"The address of b+1 is: "<<b+1<<endl;
cout<<"*(b+1) is: "<<*(b+1)<<endl<<endl;
cout<<"The address of &b is: "<<&b<<endl;
cout<<"The address of &b+1 is: "<<&b+1<<endl<<endl;
return 0;
}
It would be something similar to this program.
W the next line prints 0012FFAC coute The address of bisp address of b+1 is: "b+lecendl;4 coutse The address of &b is:bocendl; Ws coutss The address of &b is:&blecendl endl; 6 return 0 a. At point Ithe program outputs 210. Why? ( points) b. At polnt 2 the program outputs 4. Why? (2 points) c. At point 3 the program outputs 105. Why? 3 points) having a he d, what will be printed at point 42001300 ,r HoS. S2- l2 (1+3poins 0012 FFAC 1219 21 lbt 0 01300S e. What will be printed at point 5? (I+ 3 points) g print 0012AC/ because Ibis kesmp fue acecho, f b opva f What will be printed at point 6? (+3 points) 2. l0 2 013007e 23 b.Explanation / Answer
The output of each line of code
------------------------------------------------------------------------------------------------------------------------------------
cout<<sizeof(b)<<endl;
output:24
as b is 2d array having 3rows, 2 columns total 6 location. each location takes 4 bytes of memory.
So 4*6= 24 bytes
------------------------------------------------------------------------------------------------------------------------------------
cout<<sizeof(b+0)<<endl;
Output: 4
it will print size of b[0] that is 4 bytes
------------------------------------------------------------------------------------------------------------------------------------
cout<<sizeof(*(b+0))<<endl;
Output: 4
it will print the size of the element stored at b[0] location that is 4 byte.
------------------------------------------------------------------------------------------------------------------------------------
// the next line prints 0012FF4C
cout<<"The address of b is: "<<b<<endl;
output: address of b here given starting address is 0012FF4C
------------------------------------------------------------------------------------------------------------------------------------
cout<<"The address of b+1 is: "<<b+1<<endl;
it will print the address of 1st row of b. each row take 8 bytes of memory here
so 0012FF4C+8= 0012FF54
------------------------------------------------------------------------------------------------------------------------------------
cout<<"*(b+1) is: "<<*(b+1)<<endl<<endl;
it will print the address of the 1st row of b. each row take 8 bytes of memory here
so 0012FF4C+8= 0012FF54
------------------------------------------------------------------------------------------------------------------------------------
cout<<"The address of &b is: "<<&b<<endl;
output: 0012FF4C
it will print staring address of b.
------------------------------------------------------------------------------------------------------------------------------------
cout<<"The address of &b+1 is: "<<&b+1<<endl<<endl;
Output: 0012F64
Reason: it will print the staring address of next array of b that addresses after 6th location of b
because b is 3 row 2 columns.
0012F4C, 0012F50,0012F54,0012F58,0012F5C,0012F60,
0012F64,
------------------------------------------------------------------------------------------------------------------------------------