Tuesday, September 10, 2013

Compiler in C Programming

What is a Compiler?

Program Compiler Image
Program Compiler
A program that translates source code into computer executable machine code or object code. The compiler invents its name from the way it works, observing at the whole portion of source code and collecting and rearranging the instructions. Thus, a compiler differs from an interpreter, which studies and performs each line of source code in sequence, without looking at the complete program. The benefit of interpreters is that they can execute a program instantly. Compilers need some time before an executable program emerges. The compiler is only a program and cannot fix your programs for you. If you make an error, you have to accurate the syntax or it won't compile.Each high-level programming language derives with a compiler. In effect, the compiler is the programming language, because it describes which commands are acceptable.

Since compilers convert source code into object code, which is unique for each type of computer machine, many compilers are existing for the similar language.

Writing your first C program

Let us write a program which displays the message “Hey Man!" on the screen. It looks like this:

  #include <stdio.h>
   main()
   {
     printf( " Hey Man! " );
   }

Compile & Execute C Program:

Lets look at how to save the source code in a file, and how to compile and run it. Following are the simple steps:


  1. Open a text editor and add the above-mentioned code.
  2. Save the file as hey.c
  3. Open a command prompt and go to the directory where you saved the file.
  4. Type gcc hey.c and press enter to compile your code.
  5. If there are no mistakes in your code the command prompt will take you to the next line and would generate a.out executable file.
  6. Now, type a.out to execute your program.
  7. You will be able to see “Hey Man!” printed on the screen

Posted By Prashant K Neelratan

0 comments:

Post a Comment