×
☰ Menu

First C program, Hello World

 

#include<stdio.h>
	int main ()
	{
		printf(“Hello World\n”);
		return 0;
	}

 

#include<stdio.h>

We include a file called stdio.h (Standard Input/Output header file) with this line of code. This file allows us to use certain commands for input and output in our software. (Think of it as lines of code commands) that someone else has written for us. It features input commands like reading from the keyboard and output commands like printing items on the screen, for example.

int main()

The return value is represented by an int (in this case of the type integer). It will be described later on what it was used for. There must be a major character in every program (). It serves as the beginning point for all programs.

 { } 

The two curly brackets (one in the beginning and one at the end) are used to group all commands together. In this case all the commands between the two curly brackets belong to main(). The curly brackets are often used in the C language to group commands together. 


Printf(“Hello World\n”); 

The printf is used for printing things on the screen, in this case, the words: Hello World. As you can see the data that is to be printed is put inside round brackets. The words Hello World are inside inverted commas, because they are what is called a string. (A single letter is called a character and a series of characters is called a string). Strings must always be put between inverted commas. The \n is called an escape sequence. In this case, it represents a newline character. After printing something to the screen you usually want to print something on the next line. If there is no \n then the next printf command will print the string on the same line.

Commonly used escape sequences are:

\n (newline)
\t (tab)
\v (vertical tab)
\f (new page)
\b (backspace)
\r (carriage return)

After the last round bracket there must be a semi-colon. The semi-colon shows that it is the end of the command. (So in the future, don’t forget to put a semi-colon if a command ended).

return 0;

When we wrote the first line “int main ()”, we declared that main must return an integer int main (). (int is short for integer which is another word for number). With the command return 0; we can return the value null to the operating system.