help needed with this question

Go down

help needed with this question

Post  gumber on Sun Sep 07, 2008 3:10 am

Code:
int main()
{
printf("%u %u",sizeof(main),sizeof(main()));
return 0;
}

can somebody plz explain me the output of this program
Question

gumber

Posts : 2
Join date : 2008-08-31

View user profile

Back to top Go down

@gumber bhai

Post  prani on Sun Sep 07, 2008 11:06 am

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/

prani

Posts : 15
Join date : 2008-08-12

View user profile

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum