The following code is that I wrote to test my understanding of using for-loop
in C
, and using assignment statement inside for-loop
in particular. But here I am getting unexpected output. Why does it do not assign 0
to the first 10 element of the array
?
And why does it do not print the array
at all if I declare the array as array[10]
instead of array[11]
?
Can anybody explain ?
#include <stdio.h>
int main() {
int i, array[11]; //array[10]
for (i = 0; ((i < 10) || (array[i] = 0)); ++i);
for (i = 0; ((i < 10) && (printf("%d\n", array[i]))); ++i);
return 0;
}