Function:
- Function is block of instructions that performs a task.
- C Program execution starts with main() function.
- OS invokes main() function automatically to start the program.
The prototype(syntax) of main() function as follows:
- The prototype of main as follows
- int main(int argc, char* argv[])
- The signature of function is used to read arguments from command line.
- main() signature is optional if we are not using command line arguments.
Any one of following definitions allowed for main():
- We can define main() method in any one of the following ways.
- Main() method by default return type is int, hence we return any int value to avoid compilation warnings.
Library functions:
- C library is a collection of header files.
- Header file is a collection of functions.
- In the previous examples, we used few functions.
We can write user functions depend on application:
- Function is a block of instructions that performs a task.
- Function takes input, process input and return output.
- The Syntax and Definition of function as follows
Every function consists:
- Prototype: It is a single statement; it is used to specify the function memory representation.
- Definition: It is a block. It contains function logic to perform the task.
- Call: It is a single statement. It is used to access the function logic
Calling the function:
- We must call the function explicitly after definition.
- Function logic executes only when we invoke.
- Main() function executes implicitly by OS.
- Other functions must be called explicitly by programmer.