H! there
I am learning C++. While the author of this website (called CPlusPlus.com) seems to be good enough, sometimes he does miss out on explaining a few things, that I keep wondering, till either I keep experimenting and thus understand, or refer the Internet.
This time, it is the arrays chapter I have reached. In the code I am giving below, he never explained in the first place why an alien variable should be in the array's square brackets in the first place, let alone how all the figures of the array are adding up automatically, without having given any such instructions. The second one I guess, "assume" rather, that when you want to add up all the figures, this is what you have to do-- this is its formula.
While searching something earlier, I happened to reach this site, and understand there are a few good experts here. Explain to me too how and why should an alien variable be placed inside the square brackets of an array.
After running this code we get: "12206".
Thanks
I am learning C++. While the author of this website (called CPlusPlus.com) seems to be good enough, sometimes he does miss out on explaining a few things, that I keep wondering, till either I keep experimenting and thus understand, or refer the Internet.
This time, it is the arrays chapter I have reached. In the code I am giving below, he never explained in the first place why an alien variable should be in the array's square brackets in the first place, let alone how all the figures of the array are adding up automatically, without having given any such instructions. The second one I guess, "assume" rather, that when you want to add up all the figures, this is what you have to do-- this is its formula.
While searching something earlier, I happened to reach this site, and understand there are a few good experts here. Explain to me too how and why should an alien variable be placed inside the square brackets of an array.
Code:
int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;
int main ()
{
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
Thanks
Comment