-7
ARRAY_SIZE[10] = {0};
int i;
for(i = 0; i < ARRAY_SIZE; ++i ) {      
  printf("Before assignment %d\n", array_of_ints[i]);   
}

I was expecting the print out result be 0 thru 9, since ++i increments i. And on the second loop it will print out 1, on the following 2, and so on. However, it prints out 0 ten times. Why is that? Thanks ahead.

SU3
  • 5,064
  • 3
  • 35
  • 66
  • `ARRAY_SIZE` is not the array size. Try 10... – Stargateur Mar 27 '18 at 05:43
  • You don't provide all code or your code doesn't compile. – freestyle Mar 27 '18 at 05:43
  • 4
    Please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask), and learn how to create a [**Minimal, Complete, and Verifiable Example**](http://stackoverflow.com/help/mcve). The code you have is to minimal, it's not complete, and it's not verifiable. – Some programmer dude Mar 27 '18 at 05:45
  • and it does print out 0 to 9. if I add this two lines: `//array_of_ints[i] = i; //printf("After assignment %d\n", array_of_ints[i]);` – pumkinthatcodes Mar 27 '18 at 05:58
  • 1
    First you have to provide minimal code so that one can compile and check. Regarding your code, you are printing `array_of_ints` and expecting result of `i`. – hafeez Mar 27 '18 at 06:00
  • 1
    what should `ARRAY_SIZE[10] = {0};` mean? there is no `array_of_ints`defined. We are not clairvoyant. – Kami Kaze Mar 27 '18 at 06:02

1 Answers1

0

ARRAY_SIZE will not give you the length of the array. You have to enter it manually.

ARRAY_SIZE[10] = {0}; 
int i; for(i = 0; i < 10; ++i ) 
{        printf("Before assignment %d\n", array_of_ints[i]);    

}
AsthaUndefined
  • 1,111
  • 1
  • 11
  • 24