Sweety said:
hello to all members,
i have strange question in C.
main()
{
printf("%d",main) ;
}
here o/p is same for all m/c in TC++ version 3.0 i.e 657.
I think this is not garbage.
what u think??
It's garbage. More specifically, the program invokes
undefined behavior, and anything at all might happen. On
the system you are using at the moment, "anything at all"
appears to be "print 657," but that is not guaranteed.
The program exhibits undefined behavior for two reasons,
and "peculiar behavior" for two more:
- It calls a variadic function without a prototype in
scope. Functions that take a variable number of
arguments -- like printf() -- must be properly
declared before use, or undefined behavior results.
The best way to declare printf() is to #include
<stdio.h>.
- It uses the "%d" conversion specifier with a value
that is not an `int'. `main' in the printf() call
is a pointer to the function named `main', and a
function pointer is not an `int'. When you tell
printf() to expect an argument of one type (`int')
and actually supply something different (function
pointer), undefined behavior results.
- It fails to end its final (only) line of output with
a newline character '\n'. On some implementations,
the output may not appear at all unless each line
ends with a newline.
- It "drops off the end" of the `int'-valued function
main() without returning an `int' value. If the
environment tries to use the value returned by main()
as an indication of the program's success or failure
(most environments do this), great confusion can
result if main() fails to return a value.