Software & Finance

Turbo C Graphics - initgraph function

initgraph function is used to initialize with the graphics library and changes to the graphics screen for drawing. It is the first step you need to do during graphics programming. The sample code is given below on this page.


You need to pass the graphics driver and graphics mode to this function. Usually we will use VGA and VGAHI for graphics driver and mode (640 x 480 pixels) respectively. Alternatively you can use detectgraph to find out the driver and mode for you.


It is quite often that you will see the linker error message when you do compile and link program - Linker Error: Undefined symbol _initgraph in module. Click here for more information on this.


Back to Turbo C Graphics Index

Source Code

#include <graphics.h>

#include <stdio.h>

#include <math.h>

#include <conio.h>

#include <dos.h>

#include <stdlib.h>


void main()


      int i, grd, grm;

      int x, y, w, gresult;


      initgraph(&grd, &grm, "");


      gresult = graphresult();

      if(gresult != grOk)




              return 0;







Output [in graphics screen]