Tuesday, August 10, 2010

Programming in C: A Small note on Functions.

printf, getchar(),putchar() all are C functions. No fuction can be split between files. 'main' function returns a value ,zero if normal termination or nonzero erroneous termination. The function prototype agree with the definition and uses of the function. If the actual arguments are more than the formal arguments, the extra arguments are discarded. And if the actual arguments are smaller than the formal arguments extra formal arguments are initialized to some garbage values. Automatic variables do not retain their values from one call to the next and must be set upon each entry. Any expression may follow a return statement. To assure a high degree of portability between programs a function should generally be coded without involving any I/O operations.Function returns int as default.To assure a high degree of portability between programs, a function should generally be coded without involving any I/O operations.

If a function fails to return a value its value is certain to be garbage. We can also compile three source files using 'cc' command which contain the program functions.

$ gcc main.c fun1.c fun2.c

Consider the statement, x = function1() + function2();

Here the order in which the calculation, function1() may be evaluated first or function2() may. C cannot specify such an order.

No comments:

Post a Comment