In my program, after I enter the first input. I expected the values to get printed because of the printf
statement next to scanf
, but for the first time alone it's not getting printed.For the next iterations and all its working correctly
Ex:
Output :
Enter input10
12
i=0,a[i]=11896224
Enter input
Code:
#include<stdio.h>
#include<stdlib.h>
int func(int *, int);
int *a;
int main()
{
int length = 5;
a = (int *)malloc(sizeof(int)*length);
for (int i = 0;i < length;i++)
{
printf("Enter input");
scanf("%d\n", &a[i]);//100,104,108,112,116
printf("i=%d,a[i]=%d\n", i, &a[i]);/*Print Statement which is not executing for first time*/
}
func(a, length);
return 0;
}
int func(int *b, int length)
{
printf("Length=%d", length);
for (int j = 0;j < length;j++)
printf("b[%d]=%d", j, b[j]);//
return 0;
}