Home A First C Program
mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday1
mod_vvisit_counterYesterday0
mod_vvisit_counterThis week1
mod_vvisit_counterLast week0
mod_vvisit_counterThis month1
mod_vvisit_counterLast month0
mod_vvisit_counterAll days4219

We have: 1 guests online
Your IP: : 38.107.179.234
 , 
Today: May 21, 2012

Tracker

visitors by country counter
flag counter

A First C Program

The first example program in K&RC is the first example program in any language: print or display a simple string, and exit. Here is my version of K&RC's program:

/*C Program to display string*/

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

printf("My name is Bibek.\n");

getch();

}

The first line is practically boilerplate; it will appear in almost all programs we write. It asks that some definitions having to do with the "Standard I/O Library'' be included in our program; these definitions are needed if we are to call the library function printf correctly.

The third line says that we are defining a function named main.

The braces {and} surround a list of statements in C.

clrscr(); clears the screen of previous output.

The line printf ("Hello, world! \n");

is the first statement in the program. It asks that the function printf be called; printf is a library function which prints formatted output. The parentheses surround printf's argument list: the information which is handed to it which it should act on. The semicolon at the end of the line terminates the statement.

The second last line getch(); ends a program.

/* …. */ is a comment statement and it does not run during execution of program.