help needed with this question
2 posters
Page 1 of 1
help needed with this question
- Code:
int main()
{
printf("%u %u",sizeof(main),sizeof(main()));
return 0;
}
can somebody plz explain me the output of this program
gumber- Posts : 2
Join date : 2008-08-31
@gumber bhai
The sizeof operator cannot be used with the following operands:
* Functions. (However, sizeof can be applied to pointers to functions.)
* Bit fields.
* Undefined classes.
* The type void.
* Dynamically allocated arrays.
* External arrays.
* Incomplete types.
* Parenthesized names of incomplete types
lekin agar we pass incomplete object type to sizeof(),then it returns 1
so output of sizeof main is 1
However incase of sizeof(main()) the answer is 4
as main returns an int,
and sizeof(main()) returns the sizeof(int)
source:http://bytes.com/forum/thread215262.html
source:http://forums.msdn.microsoft.com/en-US/vclanguage/thread/88e0c0ea-cc96-4ee4-9393-1afc255afc51/
* Functions. (However, sizeof can be applied to pointers to functions.)
* Bit fields.
* Undefined classes.
* The type void.
* Dynamically allocated arrays.
* External arrays.
* Incomplete types.
* Parenthesized names of incomplete types
lekin agar we pass incomplete object type to sizeof(),then it returns 1
so output of sizeof main is 1
However incase of sizeof(main()) the answer is 4
as main returns an int,
and sizeof(main()) returns the sizeof(int)
source:http://bytes.com/forum/thread215262.html
source:http://forums.msdn.microsoft.com/en-US/vclanguage/thread/88e0c0ea-cc96-4ee4-9393-1afc255afc51/
prani- Posts : 15
Join date : 2008-08-12
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum