C/How many bytes
Expert: Zlatko - 1/11/2010
QuestionHello.
I'm trying to check how many bytes are occupied by function scanf("%d",&i) (where i is int).
I tried to write this:
printf("%d\n",sizeof(scanf("%d",&i)));
and program writes number 2.
I don't know, if this result is correct (only two bytes for this function?) or incorrect. Was my method correct?
AnswerHello Rudolph.
It is not possible to find how many bytes a function occupies in this way. What sizeof is returning here is the size of the return value of the function. I don't know why it is 2 in your case. Perhaps you are using a very old system. On my system it returns 4.
Try this:
int i(void) {}
short s(void) {}
int main(void)
{
printf("%d\n", sizeof(i()));
printf("%d\n", sizeof(s()));
}
I get results of 4 and 2, matching the size of the return values of the functions.
Best Regards
Zlatko