-4
\$\begingroup\$

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?

\$\endgroup\$

closed as off-topic by Alexandre Vaillancourt, Josh Jan 15 '16 at 16:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Alexandre Vaillancourt, Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    \$\begingroup\$ This should be on stackoverflow since this is not related to gamedev. \$\endgroup\$ – DH. Jan 15 '16 at 16:09
  • 2
    \$\begingroup\$ 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 \$\endgroup\$ – rlam12 Jan 15 '16 at 16:21
  • \$\begingroup\$ Sorry...I was too excited about developing. \$\endgroup\$ – Jithesh Jan 16 '16 at 5:57
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ String must be std::string. \$\endgroup\$ – HolyBlackCat Jan 15 '16 at 16:10
  • \$\begingroup\$ @HolyBlackCat You would be correct. I don't work in C so my syntax and proper declarations are more than rusty, but examples are valid no matter what language. \$\endgroup\$ – Draco18s Jan 15 '16 at 16:12
  • \$\begingroup\$ That's ok, answer and examples are good. I just decided to tell it to you instead of editing. \$\endgroup\$ – HolyBlackCat Jan 15 '16 at 16:14
  • \$\begingroup\$ @HolyBlackCat Just edit it, dude, I won't be offended. :) I've accepted a couple of edits where the editor was more correct than I had been (variable naming, for instance), or for minor things like syntax errors or spelling. Comments just makes me think, "FFS, just edit it yourself." \$\endgroup\$ – Draco18s Jan 15 '16 at 16:17
-1
\$\begingroup\$

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

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.