First C language Program
Lets see how to write a simple c program
#include <stdio.h> #include <conio.h> int main() { printf("Hello,World"); getch(); return 0; }
Different parts of C program.
All these are essential parts of a C language program.
Pre-processor
#include, the first word of any C program. It is also known as pre-processor. The main work of pre-processor is to initialize the environment of program, i.e to link the program with the header file <stdio.h>.
Header file
Header file is a collection of built-in functions that help us in our program. Header files contain definitions of functions and variables which can be incorporated into any C program by pre-processor #include statement. Standard header files are provided with each compiler, and cover a range of areas like string handling, mathematical functions, data conversion, printing and reading of variables.
To use any of the standard functions, the appropriate header file must be included. This is done at the beginning of the C source file.
For example, to use the printf() function in a program, the line #include <stdio.h> is responsible.
main() function
main() function is a function that must be used in every C program. A function is a sequence of statement required to perform a specific task. main() function starts the execution of C program. In the above example, int in front of main() function is the return type of main() function. we will discuss about it in detail later. The curly braces
{ }
just after the main() function encloses the body of main() function.Compile and Run
There are many different ways to compile and run a C program. All that is required is a C compiler. We will recommend you to use turbo c IDE, oldest IDE for c programming. It is freely available over internet and is good for a beginner.
Step 1 : Open turbo C IDE(Integrated Development Environment), click on File and then click on New
Step 2 : Write the above example as it is
Step 3 : Click on compile or press Alt+f9 to compile the code
Step 4 : Click on Run or press Ctrl+f9 to run the code
Step 5 : Output
No comments:
Post a Comment