0
#include <stdio.h>

int main () 
{
    int size,i;
    int arr[size];

    printf ("Enter size of array\n");
    scanf ("%d",arr[size]);

    for (i=0; i<=size; i++)
    {
        printf ("%d", arr[size]);
    }

    return 0;
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335

1 Answers1

3

I have not understood the question but your code is invalid.

Before declaring the variable-length array arr the variable size must to have already a positive value. So you need to write at least like

int size,i ;

printf ("Enter size of array\n") ; 
scanf ("%d", &size) ;

int arr[size] ;

This call of scanf

scanf ("%d",arr[size]);

does not make any sense, not least because the second argument of the call must be a pointer.

Also, the condition in the for loop must look like

for (i=0; i <size; i++) {
          ^^^^^^^

And you are trying to output a non-existent element of the array

printf ("%d", arr[size]);

The valid range of indices for this variable-length array is [0, size).

It seems you mean

printf ("%d ", arr[i]);

But before outputting elements of the array you need to assign values to them because the array is not initialized and you may not initialize a variable-length array at its declaration.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335