top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How memory can be allocated for the array in the following program?

+2 votes
365 views
#include <stdio.h>

int main(void)
{
  int a=17;
  scanf("%d",&a);

  int arr[a];

  printf("%lu",sizeof(arr));
}

Memory for array "arr" should be allocated at compile time but in this case it takes the value of "a" from the user(run-time) and allocates the same size for the array.

posted May 12, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Nice question,
Please note that allocation of memory is done at run time not compile time,
During compilation compiler will just create a table for this variable, but actual allocation is done at run time.

answer May 13, 2016 by Chirag Gangdev
...