Tuesday, November 07, 2017

First C Program and Compilation and Execution of C program

Program 1.1: To write the first c program to print the “Hello C language”.

Open the C console and write the following code.

¾     Before a C program is compiled by a compiler, source code is processed by a program called preprocessor. This process is called preprocessing.
¾     Commands used in preprocessor are called preprocessor directives and they begin with “#” symbol.
¾     #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.
¾     The printf() function is used to print data on the console. The printf() function is used for output. It prints the given statement to the console.
¾     The syntax of printf() function is given below:

printf("format string",argument_list); 

¾     The format string can be %d or %i (integer), %c (character), %s (string), %f (float) etc.
¾     The semicolon (;) is a statement terminator in C to help the parser figure out where the statement ends.
¾     The getch() function asks for a single character. Until you press any key, it blocks the screen.

Compilation and Execution of C program
There are 2 ways to compile and run the c program, by menu and by shortcut.
By menu              
¾     Now click on the compile menu then compile sub menu to compile the c program.
¾     Then click on the run menu then run sub menu to run the c program.
By shortcut
¾     Or, press ctrl+f9 keys compile and run the program directly.
¾     You will see the output on user screen.

You can view the user screen any time by pressing the alt+f5 keys. Now press Esc to return to the turbo c++ console.
¾           If you run the C program many times, it will append the output in previous output. But, you can call clrscr() function to clear the screen. The clrscr() function is defined in conio.h file. So it will be better for you to call clrscr() function after the main method as given below:

#include <stdio.h>  
#include <conio.h>  
void main()
   printf("Hello C Language");  


Post a Comment

C language Introduction

The C Language is developed for creating system applications that direct interacts to the hardware devices such as drivers, kernels etc. C...