phoTo get started with C programming language, there are several basics to grasp in the code structure. In this article, I will elaborate on the anatomy of a simple “hello world” program. The program will just display the words “hello world” through the code. There is also a free book available by Dennis Ritchie, who is the inventor of the C programming language.
Let us see this piece of code :
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("hello world!\n");
return 0;
}
The int main () is a function and the line printf(“hello world!\n”); and return 0; are instructions within the function.
The ‘include’ lines #include <stdio.h> and #include <stdlib.h> are files which are included to get some basic functions within the code itself. The aim is to include some built-in functionality into the hello world program.
On your Linux terminal, you just need to save the file as hello.c, set it as executable and run it with the command gcc -o hello hello.c You will notice a file called hello has been created! You can run it as ./hello to find the result ‘hello world’.