+ 1

Why does this code gives 57 as output??

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

15th Feb 2019, 5:11 PM
Sree
Sree - avatar
3 Respuestas
+ 1
n_ptr+5 coincidentally holds the value 0, so (n_ptr+*(n_ptr+5)) equals n_ptr+0 and points to the first element of the array
15th Feb 2019, 5:35 PM
Anna
Anna - avatar
+ 1
But when this statement is given, printf("%d",*(n_ptr+*(n_ptr+4))); The result is 0. Why is it so?
15th Feb 2019, 5:47 PM
Sree
Sree - avatar
+ 1
You define an array with four elements and try to access its fifth element. The memory location could contain anything, possibly a trash value, possibly another variable's value. You can't really predict the outcome
15th Feb 2019, 6:09 PM
Anna
Anna - avatar