-->
Search here and hit enter....

Function in C language ( Part 1 )

Hello Viewer! How are you I hope you well? In the previous lesson, we learned  Pointer in C language ( Part 2 ). in this lesson we'll learn Function in C language ( Part 1 )...


programming language

Man is an intelligent species, but they can't perform all the task/work/job alone. we may call a mechanic to fix up our bike, we may call a painter to paint our house. similarly, a computer program can't perform all task/work/job. it requests other program called "Function". In this part, we'll discuss "Function in C"

Function?
A function is a block of codes. each function performs a specific task. using a function is something like hiring a person to do a specific job for you. sometimes the interaction with this person is very simple & sometimes it's complex.
Suppose you have a task that is always performed exactly, in the same way, understand with example a bimonthly servicing of your motorbike. when you want it to be done, you go to the service station and say, "It's time, do it now". you don't need to give instructions, because the mechanic knows his job. you don't need to be told how the job is done. you assume the bike would be serviced in the usual way, the mechanic does it.
let's now look at simple C function that operates in much the same way as the mechanic. actually, we will be looking at two things - A function calls or activates the function and the function itself.


program

output



In the above figure we have defined two functions - main ( ), message ( ). In fact, we have used the word message at three places in the program. let us understand the meaning of each.


void message ( ) ;
The declaration indicates that message ( ) is a function which after completing its execution does not return any value because the return type is void  . It is necessary to mention the prototype of every function that we intend to define in the program.

The 2nd usages f message is...
void message ( )
{
  printf ( "Do you Know?" ) ;
}

This is the function definition. In this definition right now we are having only printf ( ), but we can also use if, while, switch etc.., within this function definition.


3rd usages

message ( ) ;
Here the function message ( ) is being called by main ( ). all program the 1st execution start with main ( ) function. in this statement 1stly control on the main ( ) function and after the main ( ) function control goes to the next statement that is message ( ). here control sees the function call ( already discussed in the previous post ) and control jumps to the declaration of message ( ) function.


Notes:
1) a C program set of one or more functions.

2) If a C program contains only one function, it must be main ( ).

3) If a program contains more than one function, then one of these function is main ( ), because program execution always starts with main ( ) function.

4) There is no limit on the number of functions that have might be present in a C program.

5)Each function in a program is called in the sequence specified by the function calls in main ( ).

6) After each function has done its thing, control returns to main ( ). when main ( ) runs out of statements and function calls, the program ends.


We know that the program execution always starts with main ( ). all C functions enjoy a state of perfect equality. No precedence, no priorities, nobody is nobody's boss/owner. one function can call other 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.




In this part of  Function in C language so enough 4 today. we'll discuss part 2 in function in the future post. I hope you like it.

Thank You 4 reading my blog!  if you have any problem or issue with this post please comment/contact.

Important :
 In this post, Article/Paragraph is taken from Let Us C book that is written by Yashavant Kanetkar.


FB COMMENTS ()