Simple Hello World Program In C
Posted: Thu Aug 26, 2010 5:13 am
Code: Select all
Were gonna save it as helloworld.c (.c as the extension tells the compiler will be using that it's a C program) on our desktop.#include <stdio.h>
main()
{printf("Hello World!\n");}
Now open up your terminal and navigate to the desktop by putting down the following terminal command.
Code: Select all
This will change the directory to our desktop.cd Desktop
We will now be using the GNU Compiler Collection (GCC) as our compiler for our program. GCC should automatically be installed on your distro if not put in the following terminal command to install the program.
Code: Select all
We will also need glibc as well, which should be already installed, and again if it's not installed put in the following terminal command to install it.
sudo apt-get install gcc
Code: Select all
Now that we have our compiler we need to compile our program that way it'll run. (Assuming you're still in the desktop directory on your terminal) Type in the following code in your terminal.
sudo apt-get install glibc
Code: Select all
Now if there's any errors in the code the compiler will automatically detect the error, but in our case we don't so in order to run our program lets put down the following terminal command, and we will now see our program.
gcc -o helloworld helloworld.c
Code: Select all
./helloworld