C: 'Hello, World!' Program

In this lesson, we will learn how to write a simple 'Hello, World!' C program, compile and run it.

Open a text editor, say, Gedit, and create a C file called hello.c

				gedit hello.c
			

Type the following C code (which prints 'Hello, World!') into it and save it

				
				#include <stdio.h>

				int main() {
					printf("Hello, World!");
					return 0;	
				}
				
			

Compile hello.c

				gcc hello.c
			

A default executable file called a.out is created. Execute it by typing the following command

				./a.out
			

The line 'Hello, World!' will be printed into the terminal.

Naming the Executable File

Instead of the default a.out, we can specify our own name for the executable file during compilation of hello.c, say hello, specified by the -o option

					gcc hello.c -o hello
				

Executing the program would now be

					./hello