In this program, the task is to create a program having a function without arguments but 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 does not accept any variable or arguments . A function can only return a single value. With line a = func() , the program passes its control to function & when function is executed , then it passes the control to main function . Then , we will display the output after calling of the function .
#include<stdio.h>
#include<string.h>
#include<conio.h>
int func();
void main()
{ clrscr();
int a;
printf("enter value of a = ");
scanf("%d",&a);
a = func();
printf("\n\n value of a after calling of function = %d",a);
getch();
}
int func()
{ int b =10;
printf("value of b inside function = %d",b);
return b;
}
#include<stdio.h>
#include<string.h>
#include<conio.h>
int func();
void main()
{ clrscr();
int a;
printf("enter value of a = ");
scanf("%d",&a);
a = func();
printf("\n\n value of a after calling of function = %d",a);
getch();
}
int func()
{ int b =10;
printf("value of b inside function = %d",b);
return b;
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.