Hi
I am new user. I have a question about sizeof() function.
First, sizeof is not a function: It is an operator, just
like + and -> and the rest. If you think about it a bit, you
will see that sizeof cannot be a function: What kind of function
could take `int' (the type name, not a value) as an argument?
I have a structure which contains char* as a member.
when I do the sizeof() on the structure, it does not know
what my char* is pointing to. So how can it give me correct value.
`sizeof theStruct' or `sizeof(struct mytype)' will give you
the number of bytes in the struct itself, including any pointers
it contains but not including whatever they point at. So, given
struct mytype { char *string; } x, y, z;
x.string = "Hi!";
y.string = "Hello, hello, hello, and welcome!"
z.string = NULL;
.... all three of `sizeof x', `sizeof y', and `sizeof z' will give
the same result: The number of bytes in one `struct mytype'. This
is true even though `strlen(x.string) != strlen(y.string)', and even
though `strlen(z.string)' cannot be computed. The number of bytes
in the struct itself is all that sizeof reports.