Compiling and executing C program in Linux

Do the following steps:
  1. Open your konsole .
  2. Open any editor, for example type "gedit &"
  3. Copy the following program code in your text editor:
    #include <stdio.h>
    int main(void){
    printf("Welcome to DA-IICT\n");
    return 0;
  4. Now save your file as "test.c"
  5. Type "gcc test.c" on your konsole.
  6. Type "ls", you will find a file by name "a.out"
  7. Now execute your program, type "./a.out" on konsole. You should get desired output.
  8. If your want to create an executable file with some othername, i.e. not as "a.out". Then use following command "gcc test.c -o test" it will create an executable file by name "test". Now type "./test" to get desired output.
Get femiliar with following Linux commands:
  • ls - list all the directory
  • mkdir - for creating new directory, e.g. "mkdir Test" will create a directory by name Test.
  • cd - change directory, e.g. "cd Test"
  • pwd - print name of current/working directory.
  • man - display mannual pages for given command, e.g. "man ls". Try out "man man" and see the output.
Last modified: Wednesday, 10 July 2013, 3:09 PM