C pointers
From wikinotes
Pointers in C work the same as they do in cpp. There are, however,
additional things to consider, mostly because C does not have strings.
*
means getting the pointer to a variable.
Note that pointers are **NOT** arrays, despite them being treated similarly
to one. Using sizeof
measures the size of the pointer, not the array.
syntax
// a pointer is just an array char *mystr = "hello"; char mystr[] = "hello"; char *names[] = { "will", "alex" }; // array(pointer) of char-arrays (strings) char **names_ptr = names; // pointer to a pointer to a char-array
basics
Pointers and Arrays are treated the same in memory.
int var[3] = {0, 1, 2, 3}; print(var[0]); //> 0 print(*var); //> 0 print(var[1]); //> 1 print(*(var + 1)); //> 1 print(var[2]); //> 2 print(*(var + 2)) //> 2