22
Some Interesting Facts about Functions in C
C

A function is a sequence of statements to perform a specific task and it can be called by other functions. A function may take some input and perform a logical unit of task and may return the response to calling function.

Interesting Facts About Functions in C

  • We can create any number of functions in a C program.
  • Function name should be unique in a C program.
  • C function can return only one value to the calling function.
  • All C programs must contain a main() function.
  • Execution of a C program comes to an end when there is no functions or statements left to execute in main function body.
  • C Functions can be invoked from anywhere within a C program.
  • There are two types of functions in C, library functions and User defined functions.

Advantage of Functions in C Programming language

  • A large C program can divide into set of functions, where each function owns the responsibility of performing one specific task.
  • Splitting a C program into functions, makes it easy to maintain and improves understandability of very large C programs.
  • We can add common utility functions in header files, So that It can be reused by other programs.
  • We can call a function any number of times in a program from any place which avoid rewriting same code again and again at various program.

Components of a function in C

-Function name : This is a C identifies representing the name of the function. Every function must have a unique name in a C program. Name of a function is used to call a function.

  • type arg1, type arg2 ..... : It is a comma-separated list of data types and names of parameters passed by the calling function. The parameter list contains data type, order, and number of the parameters expected by a function at the time of calling it. Function Parameters field is optional, we can skip it if a function don't require any data from calling function.

  • body of a function : The body of a function contains a set of statements that will be executed when this function is called. It may define it's own local variables and call other functions.

  • return(expression) : This is used to send a value to calling function before termination of function. If the return type of function is void, you need not use this line. When control reaches return statement, it halts the execution of function immediately and returns the value of expression to calling function.

Author

Notifications

?