C clrscr()

clrscr() 函数在 conio.h 头文件中定义。它有助于清除控制台或输出屏幕上显示的先前输出。清除后,它将光标移动到屏幕的左上角。


clrscr(); 


clrscr() 参数: 

clrscr() 函数不接受任何参数。

clrscr() 返回值

clrscr() 函数不返回任何值。它清除控制台窗口并移除控制台中所有内容,使其可供使用。 

clrscr() 示例 

示例 1: C 语言中 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

示例 2: clrscr() 在 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();
}

输出


Sum: 70