0% found this document useful (0 votes)
14 views9 pages

C Functions: Types of Function

Nana

Uploaded by

lovemation098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

C Functions: Types of Function

Nana

Uploaded by

lovemation098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

C Functions

A function is a block of code that performs a specific task.

Suppose, you need to create a program to create a circle and color it. You
can create two functions to solve this problem:

create a circle function

create a color function

Dividing a complex problem into smaller chunks makes our program easy
to understand and reuse.

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

Standard library functions (/c-programming/library-function)


:
User-defined functions (/c-programming/c-user-defined-functions)

Standard library functions


The standard library functions are built-in functions in C programming.

These functions are defined in header files. For example,

The printf() is a standard library function to send forma"ed output


to the screen (display output on the screen). This function is defined in
the stdio.h header file.
Hence, to use the printf() function, we need to include the stdio.h

header file using #include <stdio.h> .

The sqrt() function calculates the square root of a number. The


function is defined in the math.h header file.

Visit standard library functions in C programming (/c-


programming/library-function) to learn more.

User-defined function
You can also create functions as per your need. Such functions created
by the user are known as user-defined functions.

How user-defined function works?


:
#include <stdio.h>
void functionName()
{
... .. ...
... .. ...
}

int main()
{
... .. ...
... .. ...

functionName();

... .. ...
... .. ...
}

The execution of a C program begins from the main() function.

When the compiler encounters functionName(); , control of the program


jumps to

void functionName()
:
And, the compiler starts executing the codes inside functionName() .

The control of the program jumps back to the main() function once
code inside the function definition is executed.
:
Working of C Function

Note, function names are identifiers and should be unique.

This is just an overview of user-defined functions. Visit these pages to


learn more on:
:
User-defined Function in C programming (/c-programming/c-user-
defined-functions)

Types of user-defined Functions (/c-programming/types-user-defined-


functions)

Advantages of user-defined function


1. The program will be easier to understand, maintain and debug.

2. Reusable codes that can be used in other programs

3. A large program can be divided into smaller modules. Hence, a large


project can be divided among many programmers.

Video: C functions
:
#15 C Functions | C Programming for Beginners

Next Tutorial:
C User-defined (/c-programming/c-user-defined-
functions)
functions

Previous Tutorial:
(/c-programming/c-goto-statement)
C goto Statement

Share on:
(h"ps://www.facebook.com/sharer/sharer.php? (h"ps://twi"er.com/intent/tweet
u=h"ps://www.programiz.com/c-programming/c- text=Check%20this%20amazing
functions) programming/c-functions)

Did you find this article helpful?


:
Our premium learning platform, created with over a decade
of experience.

Try Programiz PRO


(h!ps://programiz.pro/?
utm_source=tutorial-
banner-
bo!om&utm_campaign=programiz&utm_medium=referral)

Thank you for printing our content at


:
Thank you for printing our content at
Related Tutorials
www.domain-name.com. Please check back
soon for new contents.

C Tutorial

C User-defined functions
s://programiz.pro/learn/master-c-programming?
source=nav- Search...
(/)
ng&utm_campaign=programiz&utm_medium=referral)
www.domain-name.com
(/c-programming/c-user-defined-functions)

C Tutorial

C Standard Library Functions

(/c-programming/library-function)

C Tutorial

String Manipulations In C Programming Using Library Functions

(/c-programming/string-handling-functions)

C Tutorial

C Function Examples

(/c-programming/c-functions-examples)
:

You might also like