+ 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

27th Oct 2018, 12:37 PM
Angelo
Angelo - avatar
3 Réponses
+ 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
27th Oct 2018, 12:59 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 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
27th Oct 2018, 1:01 PM
Mert Yazıcı
Mert Yazıcı - avatar
- 6
hi
27th Oct 2018, 7:16 PM
[No Name]