Hey guys I am learning the basics of C language and I am a little bit confused about how to use arrays.
I mean what are they used for?
Hey guys I am learning the basics of C language and I am a little bit confused about how to use arrays.
I mean what are they used for?
Ever made a shopping list?
That's an array of type std::string[]
. Or if you want to get really technical, it could be considered an array of type ItemConsumable[]
(because "Steve" is a valid string, but you certainly can't buy him!)
In game programming, you would just arrays (or lists) to keep track of objects, actions, events, or other data. It entirely depends on the use. You might even have a (two dimensional!) array that your units use for pathfinding.
First of all. C is not the same as C++. (They are different programming languages)
Now, (trying to explain without making it too complicated), arrays are lists of variables.
(The image has Numbers with capital letters, my fail, ignore that, shouldn´t have the starting letter in capitals)
For example, int numbers[10];
is an array that contains space for 10 ints (numbers).
You can access values from the array ("list"):
exampleIntVariable = numbers[1];
Our variable will have the value of the 2ND number in our list (The first one is numbers[0])