Tuesday, September 20, 2011

CHAPTER-2 INTRODUCING PROGRAM IN C


We are going to write a program which will just display the output “hello world”.
The function for printing  on the console is printf function.(console  means monitor).
The following statement
Printf(“hello world”);
Will print the required output.
The  printf statement should be written with in main function as
Void main()
{
Printf(“hello world”);
}
The open curly brace marks the beginning of main function.
The closing curly brace marks the end of main     function.
Normaly  in c curly braces are used to mark the beginning and end of the block.
The block is a group of one or more sentences.
Now we are going to add one more statement at the beginning of the program.
#include<stdio.h>
Void main()
{
Printf(“hello world”);
}
The include statement includes the header file stdio.h
Stdio.h-> standard inputoutput.h
What is a header file.
Headers files  are files where the library functions are declared. Printf function is declared in stdio.h
In this programming if we didn’t include the include statement the compiler will show an error as printf function prototype missing.
Proto type refers to function declaration.
Now  save the program
Now compile the program.
The compiler will show an error if we did any syntax error in the program.
Syntax refers to the grammar of c language.
After correcting the error the program will get compiled.
That means the program will be converted into machine code.
Now run the program.
Now view the program output.
When we run the program second time or running any other program the program out put will be appended at the end of the previous programs output.
To avoid this we add another library function clrscr() which will clear the screen.
The clrscr() function needs the conio.h  header file to be included.
Conio.hà console input output.h
Now the program will be
#include<stdio.h>
#include<conio.h>
Void main()
{
Clrscr();
Printf(“hello world”);
}

Previous chapter

No comments:

Post a Comment