0

Why is the size of the dynamic array b not the same as the array a, even though both have 17 elements ?

https://code.sololearn.com/c1KuxtS6JFPh/?ref=app

7th Apr 2018, 6:57 AM
Kuldeep Singh
Kuldeep Singh - avatar
7 Respuestas
+ 2
Kuldeep Singh because every pointer is 8 bit large so sizeof(b) = 8. But sizeof(b[0]) = 4, because it expects an integer at the pointers [0] position which has 4 bytes. And dividing the value with arrSize -> 2
7th Apr 2018, 11:12 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 3
because b is not really a array it just stores the address of the first int
7th Apr 2018, 7:03 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 3
7th Apr 2018, 11:15 AM
Kuldeep Singh
Kuldeep Singh - avatar
+ 2
b is not an array, it's a pointer. You divide the pointer size by what it points to.
7th Apr 2018, 11:02 AM
Timon Paßlick
+ 1
If it was a 32 bit architecture, you'd get the expected 1.
7th Apr 2018, 11:12 AM
Timon Paßlick
0
Aaron Erhardt but why is it printing 2 instead of 1 ? thx
7th Apr 2018, 10:54 AM
Kuldeep Singh
Kuldeep Singh - avatar
0
Timon Paßlick or using a long long datatype which is 8 bytes large
7th Apr 2018, 11:14 AM
Aaron Eberhardt
Aaron Eberhardt - avatar