+ 4
C language challenge code
I found this code in a C challenge, but I do not understand what it actually does. Could some of you explain it to me, please? https://code.sololearn.com/c9wBQny7U9J1/?ref=app
3 odpowiedzi
+ 11
Given:
int a[4]={0,1,2,3};
a[1]= *(a+2);
*(a+2)= a[3]++;
printf("%d", a[1]+a[2]);
'a' simply means address of a[0] (pointer to starting of array)
*a means value stored where a points i.e a[0] itself
So, lets see
a[1] =*(a+2)
//this means
// a[1] = a[0+2] , a[1] = 2
*(a+2) = a[3]++ (a[3] is 3)
// a[0+2] = 3
print a[4]+[1]
2+3
5
// answer
+ 11
arr[n] is equivalent to *(arr + n)
so
a[1] = *(a+2);
a[1] = 2
a = {0, 2, 2, 3}
*(a+2) = a[3]++
a[2] = 3++
a = {0, 2, 3, 4}
a[1] + a[2] = 5
- 6
hi