+ 1

Q2: How this non-initialized array code works?

https://code.sololearn.com/c4549pgz1XC1/?ref=app How this code works? We are comparing the addresses of two array elements. Array is contigous if the address of &arr[4]=1016 so the address of arr[23] will be = 1092. But sometimes the address is in Hex and I think the if statement can't compare hex numbers?

5th Nov 2019, 1:18 PM
Robin Singh
Robin Singh - avatar
6 Respostas
+ 2
I think they are generally in hexadecimal but it depends on what format specifier you use to display that value to the screen. For eg if you mention %d it will result in integer or %p will result in hexadecimal and so on.
5th Nov 2019, 1:33 PM
Avinesh
Avinesh - avatar
+ 2
You need not initialize an array for this particular program. As you said array has contiguous memory occupancy. Obviously an element stored at a later index will have higher memory value. And the comparison is happening correctly, there is no problem in that. Hope it answers the question.
5th Nov 2019, 1:25 PM
Avinesh
Avinesh - avatar
+ 1
Thanks I think (if statement) automatically converts hexadecimal to integer(decimal) then perform the comparision.
5th Nov 2019, 1:37 PM
Robin Singh
Robin Singh - avatar
+ 1
Robin Singh I'm not sure about that but I think you will find that out.
5th Nov 2019, 1:43 PM
Avinesh
Avinesh - avatar
+ 1
If statement won't convert hex to decimal, instead it compares both hex numbers which are actually the addresses of each index of an array.
5th Nov 2019, 5:49 PM
blACk sh4d0w
blACk sh4d0w - avatar
0
Avinesh Addresses are always in integer numbers only?
5th Nov 2019, 1:27 PM
Robin Singh
Robin Singh - avatar