You are currently viewing Functions in C programming Language – Easy explanation

Functions in C programming Language – Easy explanation

Spread the love

What is functions in C programming?

C Programming language also support functions like other programming languages. Functions is the set of statements that takes input, perform some operation and produces output.

Syntax,

return_type fun-name(set of inputs)

Why function?

Pointers in C programming Language

https://studywholenight.com/pointers-in-c-programming-language/

Function provides you the flexibility of managing code. I have listed major reasons why we must use functions in c or on any other programming languages.

  • Reusability: You can reuse same code over and over without writing same codes again and again.
  • Abstraction: If you are using the function in your program, then you don’t have to worry about how it works inside. for example scanf() function.
  • Function can divide a large program code into smaller pieces.
  • Function is declared to tell a computer about it’s existence.
  • A function is called in order to be used.
  • Function is defined to get some task done in easy way.

Types of functions in c programming

functions in c programming

a) Library function is the inbuilt functions in C programming language. built-in functions are defined inside header files. For example if we want to use printf() function then we need to include #include<stdio.h> in our program.

b) User Defined Function: User defined functions are created by programmer. We can create functions as per our need.

Basic Structure of function in C programming Language.

#include<stdio.h>
int myFunction()
{
 .............
 .............
}
int main()
{
 ............
 ............
 myFunction();
}

Program to add two numbers in C programming using function

#include<stdio.h>
int sum(int a, int b);
int main()
{
int a, b, c;
a= 5;
b= 12;
c = sum(a+b);
printf("The sum is: %d",c);
return 0;
}
int sum(int a, int b)
{
return a+b;
}


Spread the love

Santosh Adhikari

Hello, it's me Santosh Adhikari, from Kathmandu, Nepal. I'm a student of Science and Technology. I love new challenges and want to explore more on Software Quality Assurance. I want to be a professional SQA. I'm also interested in Blogging, SEO activities.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments