Bar() Function

bar() function draws a filled rectangle.

bar() function is used to draw a two dimensional rectangular bar. bar() function is similar to rectangle() function but this function also fills the rectangle by set color and style by using setfillstyle() function. It fills the rectangle with current (default) fill pattern.

void bar(int left, int top, int right, int bottom);
  • bar() function contains forr parameters left, top, right and bottom. top-left and right- bottom coordinates are required to draw the bar.
  • left specifies the X-coordinate of the top-left corner.
  • top specifies the Y-coordinate of the top-left corner.
  • right specifies the X-coordinate of the right-bottom corner.
  • bottom specifies the Y-coordinate of the right-bottom corner.





void main()


int gd=DETECT,gm;

initgraph(&gd,&gm," ");





Above program is used to draw the bar of length 100 cm and breadth of 50 cm with the top-left corner (100,150) and right bottom corner (200,200). The color filled in bar is white because white color is a default color. We can change the color of the bar with the setfillstyle() function present in the graphics.h header file.