clrscr() function in C


clrscr() is used for clearing output screen i.e. console.It is not compulsory to use in c program, but it will helpful to remove and clear unnecessary output of previous programs.

Suppose you run the program terminate the program and once again you run the program then the output of the previous program is there if you not use clrscr(). So when ever you use the clrscr(); it clear the screen. and it always declare after the variable declare.

For Example:
                               int a, b, c;
                               char ch;
                               clrscr();



Example of clrscr() function in C Programming

#include<stdio.h>

void main()
{
int i;

clrscr(); //this function clear the previous
                   //program output screen.

for(i=0;i<5;i++)
{

printf("clrscr() function test\n");

}
printf("press any key to clear screen\n");
getch();

clrscr();
printf("The screen has been cleared ! ");
getch();
}



clrscr function

4 comments:

  1. what is the reasons of writing clrscr() after variable declaration ....?

    ReplyDelete
  2. clrscr() is not compulsory to use in program. It used to clear previous output screen. mostly it used in turbo c because in turbo c when we run our program again and again it could not clear previous output screen. but in code block there is no need to used clrscr because it always clear previous output screen.

    ReplyDelete
  3. still plz specify why there is need to clrscr after declaration of variables why clrscr not after main?

    ReplyDelete
  4. its the syntax that is followed at the time of c invention, i.e after variable declaration only any executable statements should allow.

    As clrscr() is an executable statement if you place it before the variable declaration, the compiler will throw an error, but I think the developers has overcome this error in later developments but am not sure.

    ReplyDelete