-4

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?

Vaillancourt
  • 16,325
  • 17
  • 55
  • 61
Jithesh
  • 1
  • 3
  • 5
    This should be on stackoverflow since this is not related to gamedev. – DH. Jan 15 '16 at 16:09
  • 2
    I would recommend to you first learn how to use the language (C or C++… your choice) before attempting to develop a game, on your first question you asked about a basic 2D game, but if you don't know how to use the language, then that will be almost impossible to do at the moment – rlam12 Jan 15 '16 at 16:21
  • Sorry...I was too excited about developing. – Jithesh Jan 16 '16 at 05:57

2 Answers2

2

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.

-1

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.

enter image description here

(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])

Mayuso
  • 927
  • 1
  • 12
  • 25