Blog
Categories of user defined function – tccicomputercoaching.com
- April 8, 2020
- Posted by: Riddhi Dhandha
- Category: C Programming Langauge at TCCI
Here, we will learn about category of functions in C programming language.
These categories depend on Parameter and function parameter.
A parameter is a variable that we use in a function definition. An argument is the actual data that we pass to the function parameter.
Example:
#include <studio.h>
//Function declaration
int getsum(int, int);
int main(void) {
/**
* We are calling the getArea() function
* The arguments passed to the function are 10 and 20.
*/
int area = getsum(10, 20);
//output
printf(“Sum: %d\n”, sum);
return 0;
}
/**
* Function definition
* Following are the parameters of the given function getArea()
* Length
* Width
*/
int getsum(int a, int b) {
return (a+b);
}
These categories depend on Function Parameter and Function Argument:
- Function with no argument and no return value.
– To create a function with no argument and no return value we set the parameter list to void and the return type of the function to void.
For example,
void print10() {
printf(“10”);
}
- Function with no argument but returns a value.
-For this type of functions we have void in the parameter list but we set the return type to match the type of value returned by the function.
For example,
int get10(void) {
return 10;
}
- Function with argument but no return value.
-In this type of functions we have the return type set to void but the parameter list is set to accept some argument.
For example,
void getNumber(int num) {
printf(“Number: %d”, num);
}
- Function with argument and returns a value.
-In this type of functions we set both the parameter list and the return type.
For example,
float getArea(float length, float width) {
return length * width;
}
To learn more in detail about C Language, Programming Language, TCCI
Call us @ 9825618292
Visit us @ www.tccicomputercoaching.com