A computer program (except for the simplest one) cannot handle all the tasks by itself. Instead, it requests other program like entities—called ‘functions’ in C—to get its tasks done.
A function is a self-contained block of statements that perform a coherent task of some kind.
Example
main( )
{
message( ) ;
printf ( "\nCry!" ) ;
}
message( )
{ printf ( "\nSmile" ) ;
}
And here’s the output...
Smile...
Cry
Here, main( ) itself is a function and through it we are calling the function message( ). Main( ) ‘calls’ the function message( ) and it mean that the control passes to the function message( ).
The activity of main( ) is temporarily suspended; it falls asleep while the message( ) function wakes up and goes to work. When the message( ) function runs out of statements to execute, the control returns to main( ), which comes to life again and begins executing its code at the exact point where it left off. Thus, main( ) becomes the ‘calling’ function, whereas message( ) becomes the ‘called’ function.
Important points about Function
Any C program contains at least one function.
If a program contains only one function, it must be main( ).
If a C program contains more than one function, then one (and only one) of these functions must be main( ), because program execution always begins with main( ).
There is no limit on the number of functions that might be present in a C program.
Each function in a program is called in the sequence specified by the function calls in main( ).
After each function has done its thing, control returns to main( ).
When main( ) runs out of function calls, the program ends. The program execution always begins with main( ). Except for this all C functions enjoy a state of perfect equality. No precedence, no priorities.
One function can call another function it has already called but has in the meantime left temporarily in order to call a third function which will sometime later call the function that has called it.
Other C programming Related topics are
Switch statement in c programming
INTRODUCTION TO C PROGRAMMING
Programming with C an introduction part two
Data types for C programming
C PROGRAMMING CHARACTER SET
CONSTANTS IN C PROGRAMMING
PROGRAMMING C VARIABLES
C PROGRAM INSTRUCTIONS
COMPILATION AND EXECUTION OF C PROGRAM
C PROGRAMMING RULES PART ONE
C PROGRAMMING RULES PART TWO
COMPILATION AND EXECUTION OF C PROGRAM
INSTRUCTIONS TO WRITE C PROGRAM
ARITHMETIC INSTRUCTIONS TO WRITE C PROGRAM
CONVERSION OF CONSTANTS IN C PROGRAM
PRIORITY OF AR THEMATIC OPERATIONS IN C
OPERATORS ASSOCIATIVITY IN C
IF STATEMENT
MULTIPLE STATEMENTS IN IF
IF AND ELSE
NESTED IF AND ELSE
BREAK
CONTINUE AND DO WHILE IN C LANGUAGE
SWITCH IN C PROGRAMMING
FUNCTIONS IN C PROGRAMMING
Functions and usage in C part two
Coding in C functions
A function is a self-contained block of statements that perform a coherent task of some kind.
Example
main( )
{
message( ) ;
printf ( "\nCry!" ) ;
}
message( )
{ printf ( "\nSmile" ) ;
}
And here’s the output...
Smile...
Cry
Here, main( ) itself is a function and through it we are calling the function message( ). Main( ) ‘calls’ the function message( ) and it mean that the control passes to the function message( ).
The activity of main( ) is temporarily suspended; it falls asleep while the message( ) function wakes up and goes to work. When the message( ) function runs out of statements to execute, the control returns to main( ), which comes to life again and begins executing its code at the exact point where it left off. Thus, main( ) becomes the ‘calling’ function, whereas message( ) becomes the ‘called’ function.
Important points about Function
Any C program contains at least one function.
If a program contains only one function, it must be main( ).
If a C program contains more than one function, then one (and only one) of these functions must be main( ), because program execution always begins with main( ).
There is no limit on the number of functions that might be present in a C program.
Each function in a program is called in the sequence specified by the function calls in main( ).
After each function has done its thing, control returns to main( ).
When main( ) runs out of function calls, the program ends. The program execution always begins with main( ). Except for this all C functions enjoy a state of perfect equality. No precedence, no priorities.
One function can call another function it has already called but has in the meantime left temporarily in order to call a third function which will sometime later call the function that has called it.
Other C programming Related topics are
Switch statement in c programming
INTRODUCTION TO C PROGRAMMING
Programming with C an introduction part two
Data types for C programming
C PROGRAMMING CHARACTER SET
CONSTANTS IN C PROGRAMMING
PROGRAMMING C VARIABLES
C PROGRAM INSTRUCTIONS
COMPILATION AND EXECUTION OF C PROGRAM
C PROGRAMMING RULES PART ONE
C PROGRAMMING RULES PART TWO
COMPILATION AND EXECUTION OF C PROGRAM
INSTRUCTIONS TO WRITE C PROGRAM
ARITHMETIC INSTRUCTIONS TO WRITE C PROGRAM
CONVERSION OF CONSTANTS IN C PROGRAM
PRIORITY OF AR THEMATIC OPERATIONS IN C
OPERATORS ASSOCIATIVITY IN C
IF STATEMENT
MULTIPLE STATEMENTS IN IF
IF AND ELSE
NESTED IF AND ELSE
BREAK
CONTINUE AND DO WHILE IN C LANGUAGE
SWITCH IN C PROGRAMMING
FUNCTIONS IN C PROGRAMMING
Functions and usage in C part two
Coding in C functions
No comments:
Post a Comment