How to print hello world in C on Ubuntu Linux


The first things to do learning C programming language is create a “Hello World!”. I commonly use Ubuntu / LINUX for building application. So, at tthis blog, I will write all C applications  in Ubuntu.

Let’s start by creating a file called “helloworld.c” :

1
2
3
4
5
6
7
8
9
10
11
12
/*—————————-
 * Program: 1-helloworld.c
 * Author:  Yodi Aditya
 * Date:    27 March 2012
 * Description: Example print hello world in C.
 */
#include<stdio.h>

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

To execute this code :

1
2
gcc helloworld.c -o helloworld
./helloworld

It should print “Hello World!”. Now, we go to further explanation :

1. stdio.h
It’s C standard library header to handle any I/O interaction.
http://en.wikipedia.org/wiki/C_file_input/output.

2. main
When you execute this program, C compiler searching where is “main” and run it.

What you have learn?
1. You know how to create basic program in C
2. You know how to run C code in Linux using GCC


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.