I am not sure about the first question, but if you use sizeof(main()),
it gives the ans 4.
vishal@ubuntu:~/progs/c\ 09:12:57 PM >$ cat alg.c
#include<stdio.h>
int main()
{
printf("%d\n",sizeof(main()));
return 0;
}
vishal@ubuntu:~/progs/c\ 09:13:00 PM >$ gcc alg.c
vishal@ubuntu:~/progs/c\ 09:13:02 PM >$ ./a.out
4
vishal@ubuntu:~/progs/c\ 09:13:03 PM >$
The reason why it doesn't overflow is because sizeof() operator
calculates the size at compile time, and it doesn't really invoke
main().
Vishal
On Wed, Jul 27, 2011 at 9:02 PM, Charlotte Swazki
<[email protected]> wrote:
> Hi there,
>
> I have two questions,
>
> Why sizeof(main) == 1 ? (sizeof(func) == 1).
> Not 4 bytes ?.sizeof(void) == 1 too.
>
>
> And this code doesn't stackoverflow ?
> int main() {
>
> sizeof(main());
> }
>
>
>
> Thanks,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.