0

I'm trying to load a small 1D array using a for loop and for some reason I'm not getting the correct output.

int main()
{
  const int ROW = 3;
  int Table[ROW];
  for (int i = 0; i < ROW; i++)
  {
    Table[i];
  }
  for (int i = 0; i < ROW; i ++)
  {
    std::cout << Table[i] << std::endl;
  }
return 0;
}

The return I'm getting on my console is

0
0
1716919432

I would think that the output would be 0 1 2 (with the newline of course). Not sure what I'm doing wrong.

3
  • Table[i]; - That line doesn't do anything at all. Commented Nov 24, 2013 at 4:59
  • That's what I was thinking, but I'm not sure what to do to it. Commented Nov 24, 2013 at 4:59
  • You never initialized the array, so the value of each element is garbage... Commented Nov 24, 2013 at 4:59

1 Answer 1

3
Table[i];

That line doesn't do anything at all. I assume you meant:

Table[i] = i;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that makes perfect sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.