Informational Linux Blog
C – Super simple program in Ubuntu!
Are you interested in writing a basic “Hello World” program using the C programming language?If yes, then this post is for you.
Here is an example of how you can write, compile and execute a very simple C program in Ubuntu Linux. You can use any editor. For this example, I’ll use GEdit.
1. Fire up the terminal, and type:
$ gedit first.c
2. Type some code, or just past this “Hello World” example:
#include<stdio.h>
main()
{
printf("Hello World\n");
}
3. Once you have written and saved your code, return to terminal and compile:
$ gcc first.c
4. A file named a.out will be created in the same directory that you saved your program in.This is the default name of the executable that gcc creates. You can change the name of your executable, by adding the -o option followed by the name of the executable.
$ gcc -o hello first.c
5. You should now have an executable by the name hello. To execute your program type:
$ ./hello
6. If everything went well, you should see the following output:
Hello World
Congratulations! You just wrote a simple C program.
| Print article | This entry was posted by russianbandit on July 20, 2009 at 10:10 pm, and is filed under Programming, Ubuntu. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |