Why does i++
; give me weird random numbers as opposed i + 1
; in the for loop?
I am quite new to programming so I would like to understand the difference here.
My guess is that i
is somehow overwritten which makes the compiler take random numbers out of memory.
#include <stdio.h>
int main() {
int arr[100];
for (int i = 0; i < 100; i++) {
arr[i] = i + 1; //why wouldn't i++ work?
}
return 0;
}