turboc++ - Program compiles and executes without header files turbo c++ -
i'm noob in programming. teacher compiled program without pre-processor directive @ , executed , displayed output. hello world program. i'm confused without directives how able carry out "printf" function.
in "classic" ansi c (c89/90) can call non-variadic functions without pre-declaring them, long careful supplying arguments of proper type. so, if 1 properly, 1 can write formally valid c89/90 program not include standard headers. e.g.
int main() { puts("hello world"); return 0; }
in modern c not possible, since starting c99 functions have declared before being called.
now, calling printf
without pre-declaring (with prototype) caused undefined behavior in c89/90, since printf
variadic function. so, if teacher did
int main() { printf("hello world\n"); return 0; }
then he/she still has lot learn c. c89/90 program not valid, if compiled, executed , displayed output "looked fine" you.
however, can still pre-declare function manually
int printf(const char *format, ...); int main() { printf("hello world\n"); return 0; }
and end valid c89/90 program not use preprocessing directives. doing way not programming practice though.
Comments
Post a Comment