programming:c:hello_world
This is an old revision of the document!
Table of Contents
Hello world !
Exercice 1
- Open a terminal
- Create your file by writing the following command
vim ex1.c
- Enter insertion mode by pressing Insert
- Write the lines below
#include <stdio.h> int main(){ printf("Hello world !\n"); return 0 ; }
- Then press Esc key
- Write :wq
- Compile your code with the following line
gcc -Wall ex1.c -o ex1
- Then run your programm by typing “./ex1” in the terminal
Exercice 2
- Open a terminal
- Copy the content of the first exercice to the second by writing the following command
cp ex1.c ex2.c
- Open ex2.c with vim
vim ex2.c
- Edit your file so it looks like this :
#include <stdio.h> int main(){ #ifdef DEBUG printf("Hello world !\n"); #endif return 0 ; }
- Compile your code with gcc
gcc -Wall ex2.c -o ex2
- Run it with “./ex2”
- Nothing should happen, it's normal because you didn't tell the compiler to use preprocessor parts. Which are defined by the #ifdef #endif quotes
- now recompile your program with the following line
gcc -Wall -DDEBUG ex2.c -o ex2
- Run it again
- Hello world !
programming/c/hello_world.1375718329.txt.gz · Last modified: 2013/08/05 15:58 by zufd