What is Function ? How many types of it ? Explain with program.
Answers
A function is a process or a relation that associates each element x of a set X, the domain of the function, to a single element y of another set Y (possibly the same set), the codomain of the function. It is customarily denoted by letters such as f, g and h.
There can be 4 different types of user-defined functions, they are: Function with no arguments and no return value. Function with no arguments and a return value. Function with arguments and no return value.
Answer:
A function of the return value only returns one result. A function is a generated type because the type of the data it returns determines its type. Arrays, pointers, enumeration types, structures, and groups are other related types.
Explanation:
A function is a segment of clean, reusable code that executes a single, connected operation. A higher level of code reuse and improved application modularity are provided via functions. Various functions like printf() and main have already been shown to you ().
Types of functions:
A function could fall under any of the following groups:
- functions that have no arguments and no output.
- functions without return values and with arguments.
- functions with return values & arguments.
Program:
#include<stdio.h>
void statement1();
void statement2();
void starline();
int main() {
statement1();
starline();
statement2();
starline();
return 0;
}
/*function to print a message*/
void statement1() {
printf("\n Sample subprogram output");
}
void statement2() {
printf("\n Sample subprogram output two");
}
void starline() {
int a;
for (a=1;a<40;a++)
printf("%c",'*');
printf("\n");
}
#SPJ3