Would you mind explain the "array of objects" for me?


Hello Daniel, thank you for the question.

An array is a way of ordering a group of variables of the same type. You used the term "objects" in your question, but those "objects" could be any variable type at all. You can even have an array of arrays. When you declare an array, you use []. Inside the [], you put a number. The number represents the number of objects you want to make an array of.

int ary[20];

Would declare an array of 20 integers. If you need to access a certain element in the array, you can index it with the brackets and a number.

int ary[20];
ary[4] = 54;

This sets the 5th integer in the array to be 54. This brings us to another point, the first element in an array is always 0.
ary[0] = 1;

Sets the first element in the array to be 1. An easy way to loop through all the items in an array would be like this:

const int size = 20;
int ary[size];

for(int i = 0; i < size; i++)
ary[i] = i * 2;

That for loop is very commonly used for indexing arrays, as it starts on the first element and ends with the last by incrementing the i variable each iteration through the loop.

If you have any further questions, please don't hesitate to ask.

I hope this infomation was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.