Welcome back! My last post, I will explain about C functions. In this post i will tell you about types of C functions and Function declaration. So let's start.....
- Standard Functions(library functions): The functions that are inbuilt in the language compiler are library functions. printf() and Scanf() belongs to the category of library functions.
- User-Defined Functions: These are actually the user modules that are deliberately created for a specific purpose. This creation of modules results in function. Various programming constructs like looping, jumping are used with it.
Function Declaration:
A function decleration statement is also known as prototype of the function or as function prototype. Function declaration consists only of a function header; it contains no code. Function header consists of three parts:
Syntax:
return_type Function_name(argument list);
1) Return_Type: If the function has no arguments, then write void in the parentheses, else the specific return type is mentioned. If the function has two or more arguments, each is separated by comma.
2) Function_name: It is given by the programmer as in case of variables.
3) Argument list: It is not mandatory(essential) to include the names of the arguments in the argument list. The purpose of the argument list is to tell the compiler the number, data type and order of arguments. The names of arguments do not need to be the same in the function declaration and the function definition. On the other hand, if the data types do not match, the compiler will flag an error. The compiler checks the data types of the arguments in the function call to ensure that they are the same or atleast compatibility.
A semicolon follows the function header. Function declarations also provide an excellent quick reference for functions used in the program, making them excellent documentation.
For example,
int largest(int a, int b, int c);
Explanation: Above function definition tells the compiler that the return type of the function is int, name of the function is largest, and it has three arguments, all of type int. The name of argument are not significant.
0 comments:
Post a Comment