Introduction to function in C Language

Introduction to function in C Language

It is defined as named block of statements .

Advantages of function in C Language

  1. It is very easy to find and correct errors .
  2. It reduces complexity .
  3. Testing becomes easier.
  4. Bigger problems can be divided into smaller sections .
  5. They can be reused.
  6. Simple to understand a function based program.
  7. Memory can be used efficiently.
  8. un-ncessary repetition of code is reduced.

Creating a function in C Language

The syntax for creating a function is

Type Fname(Parameters)
{
Variables ;
:
:
Statements;
:
:
return( Value );
}

Type is the data types of value returned by function.

Fname is the  functions name  specified by the programmer.

Parameters are variables declared within parenthesis written after the function name. These variables are called parameters

Variables are declared within function body.

Statements is set of  instructions which would run when function is called.

return is used to return a value from function.

Value is any valid variable, constant or expression. The return type of function will depend upon it. If it is of float type, the return type would be int and so on.

Spread the love
Lesson tags: advantages of function in c, components of a function in c language, Creating a function in C Language, Defining a function in c language, Syntax of function in c language, what is a function in c
Back to: C Programming Language
Spread the love