Okay, I'm sort of confused about how sizeof works. Can I really use sizeof anywhere in the program (except #if statements) just like it is a function, or something? All of the sizeof's are replaced by the actual size of the object, right? The reason I'm asking, is this program:
#include <stdio.h>
void dosomething(int x);
int main()
{
int x;
srand((unsigned int) time());
do
x = rand();
while(x > 500);
dosomething(x);
printf("%d\n", x);
return 0;
}
void dosomething(int x)
{
char s[x];
printf("%d\n", sizeof s);
}
I didn't really think this would work, because the compiler wouldn't know what the size of s is. But it did, so does that mean that "sizeof s" is simply replaced by whatever is inside the brackets following the s in the definition?
#include <stdio.h>
void dosomething(int x);
int main()
{
int x;
srand((unsigned int) time());
do
x = rand();
while(x > 500);
dosomething(x);
printf("%d\n", x);
return 0;
}
void dosomething(int x)
{
char s[x];
printf("%d\n", sizeof s);
}
I didn't really think this would work, because the compiler wouldn't know what the size of s is. But it did, so does that mean that "sizeof s" is simply replaced by whatever is inside the brackets following the s in the definition?