N
nnaemeka.david
I wrote this program with a for loop that is misbehaving.
why does the for loop in main not output correctly when i use
a variable for the conditional step. if i change loopsie in the conditions step to the number 10, it runs correctly.
void init_array(int a[], int count){
for(int i=0; i<count; i++){
a=i*10;
}
}
int main(void) {
int my_array[5];
int loopsie=10, i;
init_array(my_array,loopsie);
for(i=0; i<loopsie; i++){
printf("element %d is %d\n", i, my_array);
}
return 0;
}
why does the for loop in main not output correctly when i use
a variable for the conditional step. if i change loopsie in the conditions step to the number 10, it runs correctly.
void init_array(int a[], int count){
for(int i=0; i<count; i++){
a=i*10;
}
}
int main(void) {
int my_array[5];
int loopsie=10, i;
init_array(my_array,loopsie);
for(i=0; i<loopsie; i++){
printf("element %d is %d\n", i, my_array);
}
return 0;
}