Static functions in C

Static functions in C

Static functions in C language basically limit the scope of methods to corresponding files.
You can also call these functions without initializing the object.

  • Static functions often enhance the usability of your code, even when the code is ready to be used again.
  • It limits the visibility of the functional scope in that particular program.

Syntax:

ref‮e‬r to:lautturi.com
static Return_Type method_name(parameters)
{
  body;
}

example:

#include <stdio.h>

//static function definition
static int sum(int a, int b){
	return (a+b);
}

int main()
{
	int number1,number2;;
	printf("Enter the number1: ");
	scanf("%d",&number1);
	printf("Enter the number2: ");
	scanf("%d",&number2);
	printf("Addition of two numbers = ");
	int res = sum(number1,number2);
	printf("%d",res);
	return 0;
}

output:

Enter the number1: 10
Enter the number2: 20
Addition of two numbers = 30
Created Time:2017-08-29 10:32:01  Author:lautturi