0% found this document useful (0 votes)
66 views

C Programming Functions

In C programming, a function is a block of code that performs a specific task. There are two types of functions: library functions, which are pre-defined in C, and user-defined functions, which are created by the programmer. User-defined functions allow programmers to decompose large programs into smaller, reusable segments, making programs easier to understand, maintain, and debug.

Uploaded by

slspa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

C Programming Functions

In C programming, a function is a block of code that performs a specific task. There are two types of functions: library functions, which are pre-defined in C, and user-defined functions, which are created by the programmer. User-defined functions allow programmers to decompose large programs into smaller, reusable segments, making programs easier to understand, maintain, and debug.

Uploaded by

slspa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C Programming Functions

In programming, a function is a segment that groups code to perform a specific task.


A C program has at least one function main( ) . Without main() function, there is technically no C program.

Types of C functions
There are two types of functions in C programming:

Library function

User defined function

Library function
Library functions are the in-built function in C programming system. For example:
main()

- The execution of every C program starts from this main() function.


printf()

- prinf() is used for displaying output in C.


scanf()

- scanf() is used for taking input in C.

User defined function


C allows programmer to define their own function according to their requirement. These types of functions are
known as user-defined functions. Suppose, a programmer wants to find factorial of a number and check whether
it is prime or not in same program. Then, he/she can create two separate user-defined functions in that program:
one for finding factorial and other for checking whether it is prime or not.

How user-defined function works in C Programming?


#include <stdio.h>
void function_name(){
................
................
}
int main(){
...........
...........

function_name();
...........
...........
}

As mentioned earlier, every C program begins from main() and program starts executing the codes
inside main() function. When the control of program reaches to function_name() inside main() function. The
control of program jumps to void function_name() and executes the codes inside it. When all the codes
inside that user-defined function are executed, control of the program jumps to the statement just
after function_name() from where it is called. Analyze the figure below for understanding the concept of
function in C programming..

Remember, the function name is an identifier and should be unique.

Advantages of user defined functions


1. User defined functions helps to decompose the large program into small segments which makes
programmer easy to understand, maintain and debug.
2. If repeated code occurs in a program. Function can be used to include those codes and execute when needed by
calling that function.
3. Programmer working on large project can divide the workload by making different functions.

You might also like