Home Docs
Graphics.h Documentation
Compiler

Basic Shapes

bar() in graphics.h

The bar() function draws a filled rectangle using the current fill style and fill color. It is useful for blocks, UI panels, and bar charts.

On This Page

Syntax

void bar(int left, int top, int right, int bottom);

Draws a solid filled rectangle from top-left to bottom-right.

Parameters

  • left, top: top-left corner
  • right, bottom: bottom-right corner

bar() fills the region; it does not only draw an outline like rectangle().

bar(100, 100, 280, 220);

Full Program

#include <graphics.h>
#include <conio.h>

int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");

    bar(80, 100, 260, 220);
    bar(300, 80, 500, 180);

    getch();
    closegraph();
    return 0;
}

Click Run (DOS) to test this quickly.

Common Mistakes

  • Confusing bar() with rectangle().
  • Incorrect coordinate order (left > right or top > bottom).
  • Forgetting to set fill style/color when needed.

Next: bar3d() and Colors & Fill.