I have found online this question: (original post: https://medium.com/@vardanator/why-cs-students-must-learn-c-as-their-main-programming-language-6d3b4f8720bd)
What is output of:
int arr[] = {1, 2, 3, 4};
int* p = arr;
int* k = p;
std::cout << (*(k + 2) + 1[p] + *(0 + arr)) << std::endl;
I think I understand correctly the *(k + 2)
and the *(0 + arr)
, but I really cannot understand how 1[p]
can be valid and what it really means.
Any simple explanation?
I guess one should not write code like this ever (or am I wrong? any case when writing something like that would be good, readable code?), but just curious.