FUNCTIONS AND PROGRAM STRUCTURE in C Programming language

C programs usually have the following form,

1.include statements
2. function prototypes/declarations
3. main() function
4. function definitions

As mentioned earlier, every C program begins from main() and program starts executing the codes inside main() function. When the control of program reaches to function_name() inside main() function, the control of program jumps to void function_name() and executes the codes inside it. When all the codes inside that user-defined function are executed, control of the program jumps to the statement just after function_name() from where it is called.
Function Declaration / Prototype
Every function in C program should be declared before they are used. Function declaration gives compiler information about function name, type of arguments to be passed and return type.
The syntax is shown below:
return_type function_name(type(1) argument(1),....,type(n) argument(n));

Example:

void Display(void);
int print_data();
xyz(); // default return type is int
double abc(int, int, char, float*);
int absolute(int);
void print_array(float*, int, int);

Function Call

Control of the program cannot be transferred to user-defined function unless it is called
invoked. The syntax is shown below:
function_name(argument(1),....argument(n));
Function Definition
Function definition contains programming codes to perform specific task.
The syntax is shown below:
return_type function_name(type(1) argument(1),..,type(n) argument(n))
{
//body of function
}
FUNCTIONS AND PROGRAM STRUCTURE in C Programming language FUNCTIONS AND PROGRAM STRUCTURE in C Programming language Reviewed by Unknown on 08:27 Rating: 5

No comments:

Powered by Blogger.