As I know, an array needs to have a specific size before compiling time in c.
I wonder why this code still works?
int s;
printf(\"enter the array si
You are confusing two things here.
1) Determining the size of an already allocated array (which your title implies): divide sizeof() for the total by the size of one (say, the first) element:
sizeof(a)/sizeof(a[0])
2) Dynamically allocating memory as your question asks:
int *a = (int*)malloc( s * sizeof(int) );