In C it is not always a compile time operation, as shown in this code:
#include <stdio.h>
#include <stdint.h>
int main(void) {
int x;
scanf("%d", &x); // Value X is not known until run-time
uint16_t data[x]; // VLA: has flexible size depending on input
printf("Value x is: %d\nSize is: %zu\n", x, sizeof(data));
// sizeof produces proper results at runtime
return 0;
}
The size of array data
is not known until runtime, and the sizeof operator still works correctly.
This is one of several reasons why C++ chooses not to support VLAs.