What is the Hello World program?:
- A very simple program to show what makes up a program
- The intent of the program is to print the following text to the screen:
Hello World Bye World
The first program, hello_world.c :
Basic Rules:
- computers are very strict about punctuations and brackets
- every statement needs to end with a semicolon
; - every open parenthesis
(must be closed with a close parenthesis) - every open curly braces
{must be closed with a close curly braces} - every open quote
"must be matched with a close quote" - every open square bracket
[must be closed with a close square bracket]
- every statement needs to end with a semicolon
- each line of code is sequentially executed
- the
mainfunction is the start of our program, analogous to start of a letter main(){}is how we define a function- function name:
main - argument list:
(), there are no arguments expected for the main function - function definition:
{}, what the function does is defined in the curly brackets - we'll discuss more about functions later
- function name:
- you can call other functions, like
printf- specify the name of the function:
printf - specify the arguments to the function:
"Hello World\n"and"Bye World\n"
- specify the name of the function:
- including the standard input/output library
#include <stdio.h>to gain more functionality- analogous to attachments in letters/emails (something you can refer to and "use" within your letter/program)
- read more about the functionalities included with this library at http://en.wikipedia.org/wiki/C_file_input/output
\ntells the computer to output a newline, read more about escaping characters at http://en.wikipedia.org/wiki/Escape_sequences_in_C- white space doesn't matter, but is necessary to allow other humans to read your code
- you can add comments to your code to explain what you are trying to do in your code
- single line comments:
// everything after the 2 slashes is ignored - multi line comments:
/* this comment can end on a different line */
- read more at http://en.wikipedia.org/wiki/C_syntax#Comments (Section Comments)
- single line comments: