07-20-2013, 05:19 PM
Hello CC Members, and welcome to my basic array tutorial!
In order for you to understand this tutorial, You'll need basic c++ knowledge such as knowing how to get input and output by including the iostream and other important things like for loops.
I'll break this tutorial into five sections:
What's an array?
By now you're probably wondering what an array is. I'll do my utmost to explain what it is.
Basically, an array is a variable that can hold multiple different values of the same type.
For example:
Hidden Content
How do we declare an array then?
Good question!
An array is usually declared like this:
Hidden Content
Here's an example of me declaring an int array:
Hidden Content
But this not enough because we need to
Initialize the array!
What does it mean to initialize an array?
Basically, when you are initializing an array, you are giving values to the integers in the array. Confusing? Here's an example of what I mean:
Hidden Content
You can leave the [] empty. What will happen then is that the compiler will give just enough space for all those numbers to fit. It basically assumes a size that matches the number of values that is between the braces {}.
Accessing the array!
Wouldn't this be useless if there were no way to access it? I think so. Luckily, you can access individual elements in the array and assign values to them. The format is as follows:
Hidden Content
It's pretty easy! Here's an example:
Hidden Content
Let's do an experiment!
Let's try and use the array to make a message!
Hidden Content
If there is something about this concept that you can't seem to 'grasp', don't hesitate to ask me questions. I won't bite, I promise!
I'm really sorry if this was hard to understand. This tutorial isn't complete yet. I'll add more things to it eventually. Thanks for reading, and I hope this tutorial helped aid you in the process of learning c++!