Function in C


In C programming, a function is a block of code that performs a specific task and can be reused throughout a program. Functions can take input in the form of parameters and can return a value or output.

Function Aspects


There are three aspects of a C function.

  • Function declaration : A function must be declared globally in a c program to tell the compiler about the function name, function parameters, and return type.

  • Function call : Function can be called from anywhere in the program. The parameter list must not differ in function calling and function declaration. We must pass the same number of functions as it is declared in the function declaration.

  • Function definition : It contains the actual statements which are to be executed. It is the most important aspect to which the control comes when the function is called. Here, we must notice that only one value can be returned from the function.

Types of function


There are two types of functions in C programming

  • Built-in functions: These are functions that are already defined in the C library and can be directly called in the program. Examples include the math and string functions mentioned previously.
  • User-defined functions: These are functions that are defined by the user (programmer) and can be used to perform specific tasks in the program.
  1. Return Type

  2. Non-Return Type

        A function in C has the following syntax:
           return_type function_name ( parameter1, parameter2, ... )
           {
                 // body of Statement ;
           }

 Return Type :

  • Int : Int as the return type if the function returns value.
  • Void : Void as the return type if the function returns no value.

 Parameter list :

  • It is a list of arguments (data_type variable_name) that will be used in the function.

Different aspects of function calling


  • function without arguments and without return value

  • function without arguments and with return value

  • function with arguments and without return value

  • function with arguments and with return value


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C