The function `clrscr()` is used to clear the console screen...

July 3, 2025 at 04:23 AM

clrscr();

The function clrscr() is used to clear the console screen in C and C++ programs. It is typically available in the conio.h header file, which is mainly used in DOS-based systems or systems supporting Turbo C/C++.

When clrscr() is called, it clears the text displayed in the terminal or console window, providing a blank screen to display further program output.

Important Notes:

  1. Header File: clrscr() requires the inclusion of the conio.h header file.

    #include <conio.h>
    
  2. Platform-Specific: clrscr() is not standard in modern compilers and environments, as conio.h is not supported in many contemporary systems like GCC, Clang, or Visual Studio.

  3. Alternatives: For non-DOS systems, clearing the screen is often done using platform-specific commands, such as:

    • Windows: Calling system("cls");
    • Linux/macOS: Calling system("clear");

Example Usage:

#include <conio.h>

int main() {
    printf("Hello, World!");
    getch(); // Wait for a key press
    clrscr(); // Clears the screen
    printf("The screen was cleared!");
    return 0;
}

In the above code:

  • The console first displays "Hello, World!".
  • After a key is pressed, the screen is cleared using clrscr(), and "The screen was cleared!" is displayed on a clean screen.

This function is mainly of historical interest, given its limited support in modern programming environments.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node