C function writing rules
Contents
- 1 Rules of Writing Function in C Programming
- 1.1 Rule 1. C program is a collection of one or more functions
- 1.2 Rule 2. A function gets called when the function name is followed by a semicolon.
- 1.3 Rule 3 : A function is defined when function name is followed by a pair of braces in which one or more statements may be present.
- 1.4 Rule 4. Any function can be called from any other function.( main also )
- 1.5 Rule 5.A function can be called any number of times.
- 1.6 Rule 6. The order in which the functions are defined in a program and the order in which they get called need not necessarily be same
- 1.7 Rule 7. A function can call itself ( Process of Recursion )
- 1.8 Rule 8. A function can be called from other function, but a function cannot be defined in another function.
Rules of Writing Function in C Programming
Rule 1. C program is a collection of one or more functions
main() { pune(); mumbai(); maharashtra(); }
Rule 2. A function gets called when the function name is followed by a semicolon.
For example :
main( ) { display( ) ; }
Rule 3 : A function is defined when function name is followed by a pair of braces in which one or more statements may be present.
For example,
display( ) { statement 1 ; statement 2 ; statement 3 ; }
Rule 4. Any function can be called from any other function.( main also )
main( ) { message( ) ; } message( ) { printf ( "\nWe are going to call main" ) ; main( ) ; }
Rule 5.A function can be called any number of times.
For example,
main() { message( ); message( ); } message() { printf("\nLearning C is very Easy"); }
Rule 6. The order in which the functions are defined in a program and the order in which they get called need not necessarily be same
main( ) { message1( ) ; message2( ) ; } message2( ) { printf ( "\n I am First Defined But Called Later " ) ; } message1( ) { printf ( "\n I am Defined Later But Called First ") ; }
Rule 7. A function can call itself ( Process of Recursion )
int fact(int n) { if(n==0) return(1); return(n*fact(n-1)); }