Tuesday, 22 January 2013

Example of how C function works:



As mentioned earlier, every C program begins from main() and program starts executing the codes inside main function. When the control of program reaches to function_name() inside main. The control of program jumps to “void function_name()” and executes the codes inside it. When, all the code inside that user defined function is executed control of the program jumps to statement just below it. Analyze the figure below for understanding the concept of function in C.



Remember, the function name is an identifier and should be unique.

Advantage of User Defined Functions:

·         User Defined functions helps to decompose the large program into small segments which makes programmer easy to understand, maintain and debug.
·         If repeated code occurs in a program. Function can be used to include those codes and execute when needed by calling that function.
Programmer working on large project can divide the workload by making different functions.

No comments:

Post a Comment