+ 5

What does this code do can you explain plse?

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

29th Sep 2019, 11:43 PM
Programmer Raja
Programmer Raja - avatar
4 odpowiedzi
+ 2
HonFu i don't get your point can you explain briefly plse
30th Sep 2019, 12:38 AM
Programmer Raja
Programmer Raja - avatar
+ 1
Hm, funny. With C you never know (unless you *know*) if it's undefined behaviour. If we ignore that, by using index notation within an array literal, you just seem to be saying: 'Write x to element [47].' You write the first three elements, then you jump (initializing the values in between with 0), then restart writing at the indexed point.
30th Sep 2019, 12:21 AM
HonFu
HonFu - avatar
+ 1
int a[50] = {1, 2, 3}; would set only the first three values, and the remaining 47 values will be auto-initialized to zero. After you initialized the array normally, you can define specific array slots like this: a[47] = 5; Now your phrase seems to combine this: First three values are regularly initialized, and then suddenly we jump to slot 47 and continue writing from there. int a = {1,2,3, [47]=47,50,60}; I have never seen this, and I don't know if this is valid C code or one of the many things in C which you you can do, but shouldn't, because they might work, but maybe won't (aka 'undefined behavior' ).
30th Sep 2019, 1:04 AM
HonFu
HonFu - avatar