Is it legal to use the sizeof operator anywhere in a C program, except in #if statements? This book says that sizeof is a compile-time operator, so would that mean I couldn't use it if the compiler can't know the size of that object? For example:
I tried doing something like this, but ended up with a Segmentation fault. I wasn't sure why I got one, so I just decided to ask the question here. Thanks in advance.Code:#include <stdio.h> void dosomething(int); int main() { srand(); dosomething(rand()); return 0; } void dosomething(int x) { char s[x]; printf("%d\n", sizeof s); }




Reply With Quote