C clrscr()

The clrscr() function is defined in the conio.h header file. It helps to clear the previous output displayed in the console or output screen.After clearing it moves the cursor to the upper left-hand corner of the screen. 


clrscr(); 


clrscr() Parameters: 

The clrscr() function does not take any parameters.

clrscr() Return Value

In clrscr() function does not return any value.It clean the   console window and make it ready to use by removing everything from the console. 

Examples of clrscr() 

Example 1: Working of clrscr() function in C?


#include <stdio.h>
#include <conio.h>

int main()
{
   printf("Before clrscr");
   clrscr();
   printf("clrscr() will clear the screen");
   return 0;
}

Output:


clrscr() will clear the screen

Example 2: How clrscr() works in C?


#include <stdio.h>
#include <conio.h>

void main()
{
   int a=30, b=40;
   int sum=0;
   clrscr();  // use clrscr() after variable declaration
   sum=a+b;
   printf("Sum: %d",sum);
   getch();
}

Output:


Sum: 70