clrscr() 函数在 conio.h 头文件中定义。它有助于清除控制台或输出屏幕上显示的先前输出。清除后,它将光标移动到屏幕的左上角。
clrscr();
clrscr() 函数不接受任何参数。
clrscr() 函数不返回任何值。它清除控制台窗口并移除控制台中所有内容,使其可供使用。
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Before clrscr");
clrscr();
printf("clrscr() will clear the screen");
return 0;
}
输出
clrscr() will clear the screen
#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();
}
输出
Sum: 70