|
|
|
|
|
|
|
|
|
|
|
|
Hello World
|
|
|
As usual, like in in other sections of my website, I start with Hello world. Open your favorite editor, and type below code and save it |
|
|
|
|
|
1 #include <stdio.h>
2
3 void main()
4 {
5 printf("\nHello World\n\n");
6 }
7
You could download file hello_world.c here
|
|
|
|
|
|
compile it by typing: |
|
|
|
|
|
gcc hello.c |
|
|
|
|
|
This creates an executable file a.out, which is then executed simply by typing its name. The result is that the characters ' Hello World' are printed out, preceded by an empty line. |
|
|
|
|
|
A C program contains functions and variables. The functions specify the tasks to be performed by the program. The 'main' function establishes the overall logic of the code. It is normally kept short and calls different functions to perform the necessary sub-tasks. All C codes must have a 'main' function. |
|
|
|
|
|
Our hello.c code calls printf, an output function from the I/O (input/output) library (defined in the file stdio.h). The original C language did not have any built-in I/O statements whatsoever. Nor did it have much arithmetic functionality. The original language was really not intended for 'scientific' or 'technical' computation.. These functions are now performed by standard libraries, which are now part of ANSI C. The K & R textbook lists the content of these and other standard libraries in an appendix. |
|
|
|
|
|
The printf line prints the message 'Hello World' on 'stdout' (the output stream corresponding to the X-terminal window in which you run the code); '\n' prints a 'new line' character, which brings the cursor onto the next line. By construction, printf never inserts this character on its own. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|