1.4 Compiling a C Program

An Overview of C>>Compiling a C Program


After downloading an IDE, now let's code a first C program. Creating an executable form of your C program consists of these three steps:
1. Creating your program
2. Compiling your program
3. Linking your program with whatever functions are needed from the library
Today, most compilers supply integrated programming environments that include an editor. Most also include stand -alone compilers.

Now, let’s write a first C program,

  • Run the Code::Blocks IDE
  • Go to File menu -> New -> Empty File or press Ctrl-Shift-N
  • In the opened new page, write the following program and save it as MyFirstProgram.c
  • Now, let’s compile the program: Go to Build menu -> Build (or press Ctrl-F9). You’ll see the following message in the bottom Build Log pane:
mingw32-gcc.exe    -c "G:\Blog Tutorials\C Tutorials\test.c" -o "G:\Blog Tutorials\C Tutorials\MyFirstProgram.o"
mingw32-g++.exe  -o "G:\Blog Tutorials\C Tutorials\test.exe" "G:\Blog Tutorials\C Tutorials\MyFirstProgram.o"  
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings (0 minutes, 2 seconds)


  • Let’s run the program, go to Build menu -> Run (or press Ctrl-F10).  You will see the “C Programming is fun!” displayed in the new blue window (without quote).
  • Alternatively, you can build and run the program by simply press F9
   //This is comment in a single line  
   #include<stdio.h> //Preprocessor directive, Header file  
   int main(){  
         printf(" C Programming is fun!");  
         return 0;  
  }  
  • Ok, you did your first program !!!

<<Back             Next>>



No comments :

Post a Comment