c - arguments of main? -
i know signature of main is:
int main(int argc, char **argv);
but don't know why main work too:
main(a){}
what's 'a' doing here? why compiler don't show error?? because havn't declare 'a' before use it.
it's feature of older c code called "implicit int". variable type not specified assumed int
. similarly, function return type not specified assumed return int
. it's considered deprecated, becomes useful in obfuscated code , code golf.
so should read as
int main(int a) {}
where int
s have been omitted because implicit.
as whozcraig mentions, standards point-of-view not conforming , not portable. pragmatically, lot of compilers let away when not in standards-conformance mode.
implicit int
behavior doesn't out of declaring variables, however.
main(a){ b,c; // int declarations c = 5; b = c + 10; d = b; // no! d not declared you, implicit int happening. return 0; }
Comments
Post a Comment