as much as i know the next code should not run.
The first problem is declaring 'int i' inside the loop and not at the start code.
The next problem is the array size is defined in run time and therefor we must use dynamiclly allocation.
I was expected to get "segment fualt".
I run it with the command:
gcc -Wall commandLineArgument.c -o ex1
int main(void){
int size=0;
printf("enter number:\n");
scanf("%d",&size);
printf("The size is: %d\n",size);
int arr[size];
for(int i= 0;i<size;i++)
{
arr[i] = 5;
}
for(int i= 0;i<size;i++)
{
printf("%d,",arr[i]);
}
printf("\n");
return 0;}
edit if variable length arrays have been supported in C since C99 then how the update code running?
gcc -Wall -std=c89 commandLineArgument.c -o ex1
int main(void){
int i;
int size=0;
printf("enter number:\n");
scanf("%d",&size);
printf("The size is: %d\n",size);
int arr[size];
printf("The size of arr: %lu\n",sizeof(arr));
for(i= 0;i<size;i++)
{
arr[i] = 5;
}
for(i= 0;i<size;i++)
{
printf("%d,",arr[i]);
}
printf("\n");
return 0;}