Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Can u explain the output for the sizes and adresses. Can you go over general

ID: 3868201 • Letter: C

Question

C++
Can u explain the output for the sizes and adresses. Can you go over general byte size and adress in c++ as well.

#include <iostream>
using namespace std;
int main( )
{int b[3][2];
cout<<sizeof(b)<<endl;
cout<<sizeof(b+0)<<endl;
cout<<sizeof(*(b+0))<<endl;
// the next line prints 0012FF68
cout<<"The address of b is: "<<b<<endl;
cout<<"The address of b+1 is: "<<b+1<<endl;
cout<<"The address of &b is: "<<&b<<endl;
cout<<"The address of &b+1 is: "<<&b+1<<endl<<endl;
return 0;
}

24

8

8

The address of b is: 0x74ef6cab0820

The address of b+1 is: 0x74ef6cab0828

The address of &b is: 0x74ef6cab0820 The address of &b+1 is: 0x74ef6cab0838

Explanation / Answer

General sizeof different data types in c++ are
char : 1 bytes
int : 4 bytes
short int : 2 bytes
long int : 8 bytes
float : 4 bytes
double : 8 bytes
wchar_t : 4 bytes

In the given scenario
the array is a 2d array of size [3][2].So in total there is 6 elements.Each element 4 bytes so 6 elements 24 bytes.
For the next two size of statements it prints 8 which is nothing but the size of the pointer.

For the next it prints the addresss of b.For the array b the starting location address is its initial address.
Each time its refering the address gets incremented according to the data type default size.