+ 2

(C challenge Question) Calling a function f with an array variable a[3], where a is an array is equivalent to:

Q. Calling a function f with an array variable a[3], where a is an array is equivalent to: --> f(a[3]) --> f(* (a + 3)) --> f(3[a]) --> all the mentioned ## its correct answer is [option 4] // i don't know how option 3 is also correct.

14th Jan 2021, 3:03 AM
BlackShadow334
BlackShadow334 - avatar
5 Antworten
+ 2
Since a[3] is translated into *(a+3), then 3[a] is translated into *(3+a), which is exactly the same, because the addition is commutative.
14th Jan 2021, 6:14 AM
Théophile
Théophile - avatar
+ 3
BlackShadow334 I don't know about other languages but I'm sure that this is working in C++, C, and not in Python. In other words, not working on all languages.
14th Jan 2021, 3:42 AM
noteve
noteve - avatar
+ 2
As far as I know, in C: array[index] == index[array]
14th Jan 2021, 3:04 AM
noteve
noteve - avatar
+ 1
《 Nicko12 》 Thanks man i didn't knew that, but is it applicable for all language or only for C.
14th Jan 2021, 3:26 AM
BlackShadow334
BlackShadow334 - avatar
0
i got this question in c challenge, and i lost it. 🤕 // i understand that option 1 and 2 are correct, but i dont understand, why option 3 is also correct. // can anyone explain this??
14th Jan 2021, 3:04 AM
BlackShadow334
BlackShadow334 - avatar