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

Functions

Functions in C are blocks of code that perform specific tasks, helping to reduce redundancy and improve modularity. There are two types of functions: standard library functions, which are built-in and defined in header files, and user-defined functions, which are created by the programmer. Key aspects of defining functions include function prototype declaration, function calling, function definition, and return type.

Uploaded by

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

Functions

Functions in C are blocks of code that perform specific tasks, helping to reduce redundancy and improve modularity. There are two types of functions: standard library functions, which are built-in and defined in header files, and user-defined functions, which are created by the programmer. Key aspects of defining functions include function prototype declaration, function calling, function definition, and return type.

Uploaded by

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

Functions in ‘C’ Language

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.

A function is a set of statements that take inputs, do some specific computation


and produces output.
Why do we need functions?
 Functions help us in reducing code redundancy.
 Functions make code modular.
 Functions provide abstraction. For example, we can use library functions
without worrying about their internal working.
Types of function

There are two types of function in C programming:

 Standard library functions


 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 formatted output to 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.

User-defined function

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

While defining functions four things need to keep in mind:


1) Function Prototype Declaration
2) Function Calling
3) Function Definition
4) Return Type
#include<stdio.h>

#include<conio.h>

void message( ); //function prototype declaration

void main( )

message( ); //function calling

void message( ) //function definition

printf(“Hello I am a function”);

}
#include<stdio.h>

#include<conio.h>

int addition(int,int);

void main()

int num1,num2,sum;

printf("Enter Two Numbers");

scanf("%d%d",&num1,&num2);

sum = addition(num1,num2);

printf("The addition of Two Numbers%d",sum);

getch();

int addition(int x, int y)

int add;

add = x + y;

// printf("Addition of Two Numbers=%d",add);

return(add);

main();

addition(x,y);

You might also like