+ 1
int main() { char str[]="%d %c ",arr[]="sololearn"; Printf (str,0[arr],2[arr+3]); }
Why answer is 115 e
5 Antworten
+ 3
Always Learn More😎 the C compiler translates array syntax into pointer references. E.g., array[5] becomes *(array+5).
In the posted code the array syntax has been swapped, but it makes no difference to the compiler, since addition can be done in either order. So 0[arr], which becomes *(0+arr) during compilation, would be the same as arr[0] or *(arr+0). That would be the letter 's' in "sololearn", which has ASCII numeric value of 115. It gets printed as digits because of the %d formatting that is specified in str.
Next, 2[arr+3] translates to *(2+(arr+3)). This simplifies to *(arr+5), or arr[5]. Look in index position 5 of "sololearn". Starting with 0, count to 5 and you come to the 6th character. It is the letter 'e'. The letter prints with character formatting (%c) as specified by str so it outputs 'e'.
+ 2
Thanks
I understood
+ 1
Please move snippet into post Description and use the title section for writing the question.
https://www.sololearn.com/Discuss/333866/?ref=app
+ 1
Thanks
0
To understand how the output came to be, you first need to understand what format specifiers are for. You can get to know them from this page.
http://www.cplusplus.com/reference/cstdio/printf/