Some basic understanding of arrays and indexes.
when you want to create an array of a
known size and initialize the array to 0:
when you want to access an element at position 5:
when you want to set the value of an array at position 7:
when you want to set the value of the array at position i to the value of i:
when you want to print the array at position i:
this:
...is not very good. Remember that when c++ creates a predefined type, if you do not initialize the value, what was in that memory location previously stays there. So, in essence, its filled with crap.
The second line copies what is in the location i to the location a. You now have two copies of crap.
Arrays start at position 0, not 1. If you want a 10 member array, you would declare
but to access this array, you would start at 0 and loop through until 9. If you went to 10, you would step outside of the array and cause a segmentation fault, which is bad.