Create and Compile C Program on Ubuntu

C language has become one of the most widely used programming languages. with C compilers from various vendors available for the majority of existing computer architectures and operating systems. C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to make utilities running on Unix. C has been standardized by the ANSI since 1989 and by the International Organization for Standardization.

The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on a PDP-7 by Dennis Ritchie and Ken Thompson, incorporating several ideas from colleagues. Eventually, they decided to port the operating system to a PDP-11. The original PDP-11 version of Unix was also developed in assembly language.

At this article, I will try to write c program, compile it and then run it on Ubuntu environment. At least 3 steps should take in creating the C program: Create the C source code, Compile the program and Execute the program.

Create the C source code

The scenario of our C program is to show the “Hello World” text on the screen. The first step is create a file with .c extension, with C syntax. I am using vi editor for this purpose. The file’s name is helloworld.c.

     printf("Hello World\n");

Compile the program

The next step is to compile the .c file to be executed program using C compiler. This section is related with build-essential package that we have discussed on the build-essential Installation on Ubuntu 18.04 Linux article. The compiled file is as hello.

ramans@ubuntu:~/testC$ gcc -o hello helloworld.c
 helloworld.c:4:2: warning: return type defaults to ‘int’ [-Wimplicit-int]

The file compiling has been done with warning, as shown above, and now there will be two files on the our directory, namely : helloworld.c and hello.

ramans@ubuntu:~/testC$ ls -ltr
total 16
-rw-r--r-- 1 ramans ramans 66 Nov 13 23:12 helloworld.c
-rwxr-xr-x 1 ramans ramans 8304 Nov 13 23:12 hello

Execute the program

The hello executable file now could be run as below.

ramans@ubuntu:~/testC$ ./hello
Hello World
Share this article via :

Leave a Reply

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