My First C language Program

 

Lets see how to write a simple c program

#include <stdio.h>
#include <conio.h>
int main()
{
 printf(" C is a programming language");
 getch();
}

Different parts of C program.

 

  • Pre-processor
  • Header file
  • Function
  • Variables
  • expression
  • Comment

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.


#include <stdio.h>
#include <conio.h>
void main()
{
 printf("Hello,World");
 getch();
}

 

#include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h .

#include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file.

void main() The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value.

printf() The printf() function is used to print data on the console.

getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.

Leave a Reply