// @topic W090120 C array syntax
// @brief Using arrays and pointers to access memory

#include <iostream>
#include <cstdlib>

int table[10] = {0};

int main()
{
    int idx = 0;
    int x;

    // the following three lines do exactly the same thing:
    x = table[idx];   // conventional
    x = idx[table];   // less conventional
    x = 0[table+idx]; // not conventional at all

label:
    int* ptr = &table[0];

    // the following three lines do exactly the same thing:
    x = *ptr;         // typical pointer dereference syntax
    x = ptr[0];       // using array syntax with pointer 
    x = 0[ptr];       // really? yes, it's still the same thing

    int MEMORY = 0;
    x = MEMORY[ptr];  // making it look a bit nicer than 0[ptr]

    // inline assebly section that loads label's address into x:
    __asm{
        push eax
        lea eax, label
        mov [x], eax
        pop eax
    }

    system("pause");
    return 0;
}