Friday, July 13, 2012

C Simple program further

stdio.h and int main ()


When we write our programs, there are libraries of functions to help us so that we do not have to write the same code over and over.
Some of the functions are very complex and long.  Not having to write them ourselves make it easier and faster to write programs.
Using the functions will also make it easier to learn to program.
Every program must have a function called main.  This is where program execution begins.
main() is placed in the source code file as the first function for readability.  There must be a function with this name or gcc can not successful compile and link your program.
The reserved word “int” indicates that main() returns an integer value.
The parentheses following the reserved word “main” indicate that it is a function.


The Function Body


A left brace (curly bracket) --  {  -- begins the body of every function.  A corresponding right brace --  }  -- ends the function body.

printf (“Hello, World!\n”) ;

This line is a C statement.
It is a call to the function printf ( ) with a single argument (parameter), namely the string “Hello, World!\n”.
Even though a string may contain many characters, the string itself should be thought of as a single quantity.  
Notice that this line ends with a semicolon.  All statements in C end with a semicolon.


return 0 ;

Because function main() returns an integer value, there must be a statement that indicates what this value is.
The statement
return 0 ;

indicates that main() returns a value of zero to
the operating system.
A value of 0 indicates that the program successfully terminated execution.
Do not worry about this concept now.  Just remember to use the statement


No comments:

Post a Comment