C program
Code:
#include<stdio.h>
int main (void)
{
int i, array[4], size;
/* print size of array on screen */
printf ("size of array : ");
/*get size of array from user */
scanf ("%d", &size);
for (i = 0; i < size; i++)
{
/* print the element of array */
printf("Enter element of array : " );
/* get array element from user and them stored into array */
scanf("%d", &array[i]);
}
return 0;
}
result
size of array : 8
Enter element of array : 1
Enter element of array : 2
Enter element of array : 3
Enter element of array : 4
Enter element of array : 5
Enter element of array : 6
Enter element of array : 7
I am confuse on size of array declaration like array[4] that means the array is capable to only four elements but if I enter size of array it store number 1 - 7. why it does not store only four numbers
if I don't give any number then its show error
hello.c: In function 'main':
hello.c:4:10: error: array size missing in 'array'
int i, array[], size;