Hi,
Could we ask you to in the future post the compiler errors that you have. It's fairly obvious in this example, but it is easier on everyone if you show the compiler output - then we can explain the errors to you.
Some questions to make you think about what is happening here.
What is the value of *q on line 18 ? Try it by printing it out with
std::cout
on line 17.
On line 28 there the same problem as on line 18. Also, What value are you trying to assign to you array? Why are you assigning to your array?
What happens on line 29? What is the value of i at this point?
Some other things:
Avoid having magic numbers in your code, make them
const
variables instead, and use that variable name in your code :
const unsigned short ArraySize = 10; // technically std::size_t is better
1 2 3 4
|
for (int i =0; i < ArraySize; i++)
{
// your code
} // make sure braces line up - it's visual thing so one can spot where the end of the loop body is
|
When using a brace initialiser list, the compile can count the number of values in the array, so you don't need to specify that.
int gradeArray[] = {1,2,3,4,5,6,7,8,9,0};
The name of an array degrades to a pointer, so no need to specify a subscript if you want to.
int* q = gradeArray;
Avoid line 5, read up on Google to see why. The easiest thing to do, is to put
std::
before each std thing. This seems a pain, and there are other ways to achieve the same thing, but this is the easiest way in the end, and all the expert coders on this site all do it that way.
Hope this helps :+)
Edit:
It is the the
+=
operator , not =+