I have read that sizeof operator in C is interpreted at compile time and since at compile time compiler knows the array size and its type,sizeof is abled to compute the number of bytes occupied by array.But how is sizeof working for the following code :
#include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d",&n);
int a[n];
int s=sizeof(a);
printf("%d",s);
return 0;
}
Here array size is not known at compile time,then how is it working properly ?
sizeof
is evaluated at run time, not at compile time. – Soubrettemalloc
ed stuff, not about VLAs. – Soubrettemalloc()
, not a VLA, variable length array). – Fanchette