I have a question about working of for loop in C. Please have a look at the following code:
#include<stdio.h>
void main()
{
int ar[10],i;
printf("Enter 10 numbers:");
for(i=0;i<10;i++)
scanf("%d",&ar[i]);
for(i=0;i<10;i++)
printf("%d",ar[i]);
}
When I execute this and give the following input:
1 2 3 4 5 6 7 8 9 10 11 12
I have given 12 inputs but the loop was supposed to run for only 10 times (scanf loop). I can give even more inputs and it is happy to take it unless I hit enter key. Is there something about for loop that I'm missing here?
Copyright Notice:Content Author:「imox」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25985824/working-of-scanf-under-for-loop