I have the next two code examples:
const char *val = strchr(ch, ' ');
const int diff = (int)(val - ch);
char arr[diff];
and
const char *val = strchr(ch, ' ');
const int diff = (int)(val - ch);
char arr[diff] = {0};
The second one generates the error like
error: variable-sized object may not be initialized
It is correct error and I understand why it happens.
I wonder why the first code snippet doesn't generate the error?
Update: Also regarding sizeof(arr) at first snippet gives the size of array, but I thought that sizeof is a compile time operator (?)