Search



Saturday, 19 September 2015

Program with Arguments & Return Values.

In this program, the task is to create a program having a function with arguments & with return values . So, we create a function outside the main function named as func() . In this function , int func is used as the function returns a variable of type int . Moreover , the function accepts an integer type variable , which are called arguments . A function can only return a single value . With line a = func(a) , the program passes its control to function & value passes will be stored in function variable a & then it returns the value to main function which is stored in main's a variabe . Then , we will display the output after calling of the function . 

#include<stdio.h>
#include<string.h>
#include<conio.h>
int func(int a);
void main()
{     clrscr();
int a;
printf("enter value of a = ");
scanf("%d",&a);
a = func(a);
printf("value of a after calling of function = %d",a);
getch();
}

int func(int a)
{   int b = a;
b = a+10;
return b;
}


No comments:

Post a Comment

Guys if you think something is wrong or should be edit than please do comment.