Functions in C Language
×


Functions in C Language

95

The block of code that performs a specific task is called a Function in C Language.

They help to organize the code and make it reusable, and easier to understand.

 functions in c language are categorized into different types based on their characteristics and purposes.

1 Built-in Functions

Built-in Functions in C are provided by standard libraries in C.

They are predefined functions, such as printf, scanf, strlen, etc.

They are directly available to use in the C Program.


2 User-defined Functions

 programmers create user-defined functions in c to accomplish specific tasks.

 These Functions are defined by users according to their needs and requirements.


3 Library Functions

Library Functions in C are provided by various libraries and header files that are included by the programmer in the C program.

Example: We include <math.h> for mathematical operation.


4 Recursive Functions

Recursive Functions in C call themselves directly or indirectly.

Recursive Functions are like problem-solving strategies where you break big problems into smaller ones.


5 Inline Functions

Inline Functions are smaller Functions defined with the Inline keyword.

The compiler takes the entire body of the function and places it directly at the location where the function is called.


6 Static Functions

Static Functions are declared with static keywords.

They are accessible within the file in which they are defined.

They cannot be accessed within the other file using the extern keyword.


7 Dynamic Functions

In C Functions are usually static, which means the compiler figures out how they work when you compile the code.

Dynamic Functions in C are resolved at run time.

There is no built-in support for dynamic functions like other programming languages.

Syntax of Functions in C Language 

return_type function_name(parameter_list){
// code to perform the task
return value;
}
Explanation

return_type:

return_type specifies the type of value function returns after performing the task.

It can be int, float, void, etc.


Function_name:

Name of function which programmer used to call from other parts of the program.


parameter_list:

the function in c takes a list of parameters as input.

The function in C takes a list of parameters as input. It is optional if the function does not require any input.


Function body:

It contains actual code that defines what the actual function does.


return value:

In C, the Function can return a value using the return statement.

When the function is called, it can perform some operations and then optionally return value to the code.

Example:

#include <stdio.h>
// Function declaration
int add(int A, int B);
int main() {
	 int N= 6, M = 3;
	 int sum = add(M, N);
	 printf("Sum: %d\n", sum);
	 return 0;
}
// Function definition
int add(int A, int B) {
	return A + B;
}
Output:

sum: 9


Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments