Right, so I picked up this tutorial a couple days ago, it went pretty good, until I got to the array part of the turorial.
Code:
Code:
billy[0] = a;
billy[a] = 75;
b = billy [a+2];
billy[billy[a]] = billy[2] + 5;
For thisa one I just don't understand what the bottom line is doing, this an example code.
Code:
// arrays example
#include <iostream>
using namespace std;
int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;
int main ()
{
for ( n=0 ; n<5 ; n++ )
{
result += billy[n];
}
cout << result;
return 0;
}
Both taken from: http://www.cplusplus.com/doc/tutorial/arrays.html
This was a full program for example that was in the tutorial, and I do not understand what the billy[n] thing is doing. If I am correct,
result += billy[n]
is:
result = result + billy[n]
But there is no billy N.
I also do not understand what this code is doing:
=
Code:
#define WIDTH 5
#define HEIGHT 3
int jimmy [HEIGHT * WIDTH];
int n,m;
int main ()
{
for (n=0;n<HEIGHT;n++)
for (m=0;m<WIDTH;m++)
{
jimmy[n*WIDTH+m]=(n+1)*(m+1);
}
return 0;
}
Why is this code acessing jimmy like this? There is no jimmy by the name of n*width+m.
Also for the part delcaring the array, is it declaring an Array with 15 indices (width * height = 3* 5)?