What are Functions in C?

Function is the collection of statements which is used to perform some specific task. It provides code reusability and code optimization.

Syntax to declare function in C

return_type function_name(data_type parameter...){
//code
}
  • return_type indicates the data type of the return value.
  • function_name specify the name of the functions.
  • Parameter are the values which is passed in the function.

A function declaration informs the compiler about a function name and how to call the function. The actual body of the function can be defined separately.
Syntax to call function in C

variable=function_name(arguments...);

Example:

#include <stdio.h>
#include <conio.h>
void sum(int a, int b);
void main()
{
clrscr();
int a, b, c;
c= sum(2,3);
getch();
}
void sum(int a, int b)
{
c = a+b;
printf(“%d”,c)
}

Output:
5

If you want to know about C Strings, refer to our C programs blog!

2 Ways of Calling Function

  1. Call by value
  2. Call by reference

Certification in Full Stack Web Development

1. Call by value

This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.

2. Call by reference

This method copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument.

Recursion

When function is called within the same function, it is known as recursion in C. A function that calls itself, and doesn’t perform any task after function call, is known as tail recursion.
Syntax

recursionfunction()
{
recursionfunction();//calling self function
}

If you want to know about File Handling in C, refer to our C programs blog!

Course Schedule

Name Date Details
Python Course 25 Mar 2023(Sat-Sun) Weekend Batch
View Details
Python Course 01 Apr 2023(Sat-Sun) Weekend Batch
View Details
Python Course 08 Apr 2023(Sat-Sun) Weekend Batch
View Details

Leave a Reply

Your email address will not be published. Required fields are marked *