With a brief search, I found some tutorials on the net.
Brief explanation:
You hold all snake units on a list.
There is head and tail, which are the first and last elements of the list. So it’s really a queue.
At each moment, determine the direction in which you must move. For example, if the direction is left, then coordinates of the next head will be in (-1.0) relative to the current head. Insert new unit in the list at head position with coordinates previously determined.
Remove the tail unit from the list (on the screen). That will organize the movement. If you find a food in the head position, start a growth counter. At each instant, countergrowth > 0, decrease it and ignore the tail unit removal. Thus, only the head will move until it grows.
references:
https://stackoverflow.com/questions/28471293/moving-snake-logic-in-processing
https://gamedev.stackexchange.com/questions/33786/snake-game-logic
http://www.codeincodeblock.com/2011/06/mini-projet-snake-game-in-c.html