-
Help please
I am beginner to c. I have to make snake game to run through microcontroller and FPGA based demo card. I have one code. I have to add some features. but i have troubles with understanding the code.
here are some declarations
typedef unsigned int snake_t;
snake_t *snake;
unsigned int snake_struct_length;
unsigned int snake_head_i;
unsigned int snake_tail_i;
#define SNAKE_EXTEND_STEP 5
unsigned int snake_extend;
and then there is a line like that
snake[snake_head_i] = new_snake_head;
i didn't get "snake[snake_head_i]" part. because snake is a pointer. so what does it mean? Could someone explain me?
-
Pointers and arrays share the same subscript notation.
With a pointer, writing ptr[index] generates the code for *(ptr+index)
So a pointer to a number of ints say gives you access to each int in that block of integers, simply by incrementing i in ptr[i] (much like you would do with an array of ints).
-
thank you for your quick reply :)