+ 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?
6 Réponses
+ 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.
+ 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.
+ 1
Thanks I think (if statement) automatically converts hexadecimal to integer(decimal) then perform the comparision.
+ 1
Robin Singh I'm not sure about that but I think you will find that out.
+ 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.
0
Avinesh Addresses are always in integer numbers only?