#include<stdio.h>
#include<conio.h>
void main()
{
int a[]={1,2,3,4,5,6};
int num,i;
for(i=6;i>0;i--)
{
a[i]=a[i-1];
}
printf("enter any no, ");
scanf("%d",&num); // input 12
a[0]=num;
for(i=0;i<=6;i++)
{
printf("\n\n%d",a[i]);
}
getch();
}
the output is 12 1 2 3 4 5 12 why??? there is no array memory problem when we do like this
#include<stdio.h>
#include<conio.h>
void main()
{
int a[]={1,2,3,4,5,6};
int num,i;
for(i=6;i>0;i--)
{
a[i]=a[i-1];
}
printf("enter any no, ");
//scanf("%d",&num);
a[0]=12;
for(i=0;i<=6;i++)
{
printf("\n\n%d",a[i]);
}
getch();
}
the memory of an array is same but the output is 12 1 2 3 4 5 6 (Now the output is change) so, when we use scanf so why the output is different
there is no mistake of Undefined Behavior and no mistake in length of an array
so plz give me the reason why this happen while using scanf????