Why students need a function list, not just a syntax sheet
Many students first meet graphics.h as a collection of disconnected programs: one file for a line, one for a circle, another for flood fill, and another for text. That approach works for passing one lab, but it becomes confusing when you try to remember which function changes color, which function draws the shape, and which function actually starts graphics mode.
A function list is more useful when it is organized by job. Instead of memorizing 40 names in random order, think in steps: start graphics mode, choose a color, draw shapes, place text, fill regions, and then exit. Once you understand that workflow, most beginner programs become easier to read and write.
graphics.h functions grouped by purpose
1. Setup and screen control
initgraph()starts graphics mode.closegraph()returns to text mode and cleans up.cleardevice()clears the full graphics screen.getmaxx()andgetmaxy()tell you the current screen boundaries.
These functions control the environment around your drawing. If a program will not even open a graphics window, start debugging from initgraph() errors.
2. Basic drawing and movement
line()draws a straight line between two points.moveto()changes the current drawing position without drawing.lineto()draws from the current position to a new point.putpixel()plots exactly one pixel.
These functions matter when you want precise control over coordinates or when you are implementing algorithms such as DDA or Bresenham from scratch.
3. Shape functions
circle()draws a circle from center and radius.arc()draws part of a circle between two angles.ellipse()draws an oval or elliptical arc.rectangle()draws a rectangular outline.bar()draws a filled rectangle.
These are the functions most students use in introductory graphics labs because they produce visible output quickly and make coordinate practice easier.
4. Color and fill functions
setcolor()changes the active drawing color.setbkcolor()changes the screen background color.setfillstyle()chooses how filled areas should look.floodfill()fills a closed region from a seed point.
These functions are where many students make mistakes, especially when boundary colors and fill colors do not match their expectations.
5. Text, image buffers, and common timing helpers
outtextxy()prints text at an exact coordinate.getimage()andputimage()copy image data to and from memory.
These functions become useful when you start creating labels, dashboards, and reusable screen content instead of static diagrams. One common non-graphics helper paired with these programs is delay() from DOS.H, which pauses execution during simple animations but is not declared in GRAPHICS.H.
15 must-know graphics.h functions for beginners
| Function | When you use it |
|---|---|
initgraph() | Start every graphics program. |
closegraph() | End the program cleanly after graphics output. |
line() | Draw a direct line between two points. |
circle() | Draw circular shapes like wheels, targets, and faces. |
rectangle() | Draw boxes, frames, windows, and charts. |
bar() | Create filled bars, blocks, and panels. |
setcolor() | Change line, outline, and text color. |
setbkcolor() | Change the screen background color. |
setfillstyle() | Select fill pattern and fill color. |
floodfill() | Fill a closed boundary from inside. |
outtextxy() | Place labels, titles, and captions. |
putpixel() | Plot individual pixels for custom algorithms. |
cleardevice() | Clear the full screen before drawing the next frame or scene. |
getmaxx() | Know the maximum x-coordinate available. |
getmaxy() | Know the maximum y-coordinate available. |
One compact example that uses the basics together
This program is useful because it combines setup, color, shapes, and text in one place. If you can explain each line in this example, you already understand the flow of many graphics.h lab programs.
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setbkcolor(BLACK);
setcolor(WHITE);
rectangle(140, 80, 500, 360);
setcolor(YELLOW);
circle(320, 180, 70);
setcolor(LIGHTCYAN);
line(140, 360, 500, 80);
setcolor(LIGHTGREEN);
outtextxy(220, 390, "graphics.h basics");
getch();
closegraph();
return 0;
}
The flow is deliberate: initialize graphics, set background, draw outlines and shapes, place a label, wait for a key press, then close graphics mode. That order will repeat in many college practical files.
A better study order for labs and vivas
Do not begin with the rarest functions. First learn the core lifecycle of a program. After that, branch into the special categories your syllabus uses most often.
- Program lifecycle:
initgraph(),closegraph(),getmaxx(),getmaxy(). - Drawing basics:
line(),rectangle(),circle(),arc(). - Appearance control:
setcolor(),setbkcolor(),setfillstyle(),bar(),floodfill(). - Annotation:
outtextxy(). - Common animation helper outside
GRAPHICS.H:delay()fromDOS.H. - Low-level and advanced topics:
putpixel(),getimage(),putimage(), palette functions, and polygon functions.
If you study in this order, your memory stays connected to actual use cases instead of isolated definitions.
Common mistakes when learning the function list
- Memorizing names without purpose. Know what problem each function solves.
- Confusing color-setting and shape-drawing functions.
setcolor()only changes the current drawing color. It does not draw anything by itself. - Treating the graphics screen like a Cartesian graph. The origin is at the top-left, and positive y goes downward. Read the coordinate system guide once and a lot of shape bugs disappear.
- Skipping cleanup. Even simple programs should exit with
closegraph().
Where to go next
If you want the broadest public reference, open the graphics.h docs index. If you want to practice immediately, use the online compiler and try the example program above. If your next lab is failing at startup, read the initgraph troubleshooting guide next.