TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Thursday, 14 May 2020

Function In C Language | Function In C Language In Hindi

Function In C Language


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


image of function in c language

Fig: Function in c 



Types of functions

 

     1)   Predefined standard library functions 

Such as puts(),gets(),printf(),scanf().  These are the functions which already have a definition in header files (.h files like stdio.h), so we just call them whenever there is a need to use them.

 

     2 )   User Defined functions 

 The functions that we create in a program are known as user defined functions.


Why we need functions in C


Functions are used because of following reasons –


a) To improve the readability of code.


b) Improves the reusability of the code, same function can be used in any program rather than writing the same code from scratch.


c) Debugging of the code would be easier if you use functions, as errors are easy to be traced.


d) Reduces the size of the code, duplicate set of statements are replaced by function calls.


Syntax of a function

return_type function_name (argument list)

{

Set of statements-block of code

}


Return_type:

 Return type can be of any data type such as int, double, char, void, short etc. Don’t worry you will understand these terms better once you go through the examples below.


Function_name: 

It can be anything, however it is advised to have a meaningful name for the functions so that it would be easy to understand the purpose of function just by seeing it’s name.


Argument list: 

Argument list contains variables names along with their data types. These arguments are kind of inputs for the function. For example – A function which is used to add two integer variables, will be having two integer argument.


Block of code: 

Set of C statements, which will be executed whenever a call will be made to the function.


Program:


#include<stdio.h>

#include<conio.h>

int  add(int num1,int num2)

{

int sum;

sum=num1+num2;

return sum;

}

int main()

{

int  var1,var2;

printf(“enter number 1:”);

scanf(“%d”,&var1);

printf(“enter number 2: ”);

scanf(“%d”,&var2);

int res=add(var1,var2);

printf(“output: %d”, res);

return 0;

}


Output:


Enter number 1: 100

Enter number 2:120

Output: 220

 


No comments:

Post a Comment