Wednesday 15 August 2012

Lets Program

Let's Discuss a Simple program in C that display "a welcome message".

/*C program to display a welcome message*/

#include<stdio.h>
main()
        {
         printf("Hello sir! welcome to the programming world \n");
         exit(0);
        }
The output of the above program will be:  Hello sir! welcome to the programming world
How to compile and execute the program?
  • First of all you need a C compiler to compile the above bunch of codes.  There's a huge number of free c compilers for windows OS available on net e.g Turbo C/C++ , Dev C++ , Eclips etc. Google any of it and install on your system. I recommend Dev c++ IDE for beginners. In Linux, terminal is enough to start with.
  • Compile the code above with any of the standard compiler and run. Voila you must get the same output as stated above.
Let's discuss the components of the above program
  • main() is a special function in C, which must exist in a C program as the execution of the program from this point.
  • printf is a standard C function called from main, used for displaying ouput.
  • "\n" indicates that the output will be displayed in a newline.
  • 'stdio.h' is a header file responsible for input-output function.
  • exit() is also a standard function that terminates the program after execution. It takes a value as parameter. In the program above it takes 0 as parameter. But it is actually not needed here as it has been used after the last line. Hence without using this function, the program will terminate automatically after displaying the output.

No comments:

Post a Comment