Explain C Program by a story

We have already discussed a simple program at Get started section. Here it is explained again by a story for very beginner.let us consider few hours activities of Mr. John:
1. He came to restaurant to take dinner
2. He ordered a menu of his favorite items
3. Waiter convey this menu to the cooker
4. Cooker cooked according to this menu

Order menu

Cooker

Now I will explain how does a c program work explaining Mr. John’s Activities. Think you are new programmer and write your first program as follows without knowing anything.
#include<stdio.h>
int main()
{
   printf("Hello world");
   return 0;
}

Now we match the lines of your  program with Mr. john’s activities. #include<stdio.h> is as like as cooking materiel. Cooker needs  some cooking materials to prepare the food according to the menu.  Mr. John’s was not concerned about the cooking materiel. He only want the food according to his menu. In the same manner as a programmer you are as like as Mr. john. Here you wanted to print “Hello world” and hence you wrote printf(“Hello world”);  You don’t need to be concerned about #include<stdio.h>. All commands have been written by  some programmers  who developed the compiler you are using.

Here int mani() is as like as waiter. Waiter was conveying the menu to the cooker. In the same manner int main()  convey the printf(“Hello world”); statement to #include<stdio.h>

All statements inside main() function must be enclosed with opening curly brace ‘{‘ and closing curly brace ‘}’
In conclusion, the simplest format of C programing is:

int main()
{
// statements goes here
}

Statements would be 1 to 1000 lines or more and at the begging there would be some #include<> header file such as #include<sdtio.h>, #include<math.h>

If you read this documentation carefully, you know how a c program works. So its time to dig into deep in the C programming field
Note: Don’t worry about return 0; You will understand how this lines works at FUNCTION topics.


Next Previous