A function is a self-contained program segment that carries out some specific, well-defined task. The function contains the set of programming statements enclosed by {}.
Functions break large computing program into smaller ones. C has been designed to make functions efficent and easy to use.
C programs generally consist of many small functions rather than a few big ones.
The use of functions avoids redundant programming of the same instructions can be placed within a single function, which can then accesses whenver it is needed.
C functions are basic building blocks in a program. All C programs are written using functions to improve re-usability, understandability and to keep track on them.
Moreover, a different set of daa can be transferred to the function each time it is accesses. C supports the user of library functions, which are used to carry out a number of commonly used operations or calculations.
Printf() and scanf() are examples of library functions. C also allows programmers to write their own functions for carrying out various individual tasks.
1.Function Declaration: A program is a set of definitions of variables and functions. Communications between the functions is through arguments and values returned by the functions.
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
2.Function call: Function can be called from anywhere in the program. The parameter list must not differ in function calling and function declaration. We must pass the same number of functions as it is declared in the function declaration.
3.Function Definition It contains the actual statements which are to be executed. It is the most important aspect to which the control comes when the function is called. Here, we must notice that only one value can be returned from the function.
return_type function_name( parameter list ) { body of the function }
SN | C function aspects | Syntax |
---|---|---|
1 | Function declaration | return_type function_name (argument list); |
2 | Function call | function_name (argument_list) |
3 | Function definition | return_type function_name (argument list) {function body;} |
A program is a set of definitions of variables and functions. Communications between the functions is through arguments and values returned by the functions.
Hello, Welcome to aimtocode
Enter some number for finding square 2 Square of the given number 2.000000 is 4.000000
Hello aimtocode
Calculate the sum of two numbers: Enter two numbers 10 24 The sum is 34
Calculate the sum of two numbers: Enter two numbers:10 20 The sum is : 30
SN | Header file | Description |
---|---|---|
1 | stdio.h | This is a standard input/output header file. It contains all the library functions regarding standard input/output. |
2 | conio.h | This is a console input/output header file. |
3 | string.h | It contains all string related library functions like gets(), puts(),etc. |
4 | stdlib.h | This header file contains all the general library functions like malloc(), calloc(), exit(), etc. |
5 | math.h | This header file contains all the math operations related functions like sqrt(), pow(), etc. |
6 | time.h | This header file contains all the time-related functions. |
7 | ctype.h | This header file contains all character handling functions. |
8 | stdarg.h | Variable argument functions are defined in this header file. |
9 | signal.h | All the signal handling functions are defined in this header file. |
10 | setjmp.h | This file contains all the jump functions. |
11 | locale.h | This file contains locale functions. |
12 | errno.h | This file contains error handling functions. |
13 | assert.h | This file contains diagnostics functions. |