Skip to content

Instantly share code, notes, and snippets.

@Miqueas
Last active October 14, 2021 04:26
Show Gist options
  • Save Miqueas/4e5a37528d085340ff36b028a94120ce to your computer and use it in GitHub Desktop.
Save Miqueas/4e5a37528d085340ff36b028a94120ce to your computer and use it in GitHub Desktop.
[C] Cursed or interesting?
#include <stdio.h>
/* Explanation
Arrays in C are just pointers. So, basically they points
to the address of the first element and when we indexing
using [], we're just performing an addition and the order
doesn't matter at all for that operator in C. Also, the
array identifier is also the first element itself, as I
said, is just a pointer.
*/
int main(void) {
int arr[4] = { 1, 2, 3, 4 };
printf("*arr: %d\n", *arr);
printf("1[arr]: %d\n", 1[arr]);
printf("*(arr + 2): %d\n", *(arr + 2));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment