Parameters
| Name | Type | Description |
|---|---|---|
x | int | The new x-coordinate for the current graphics position. |
y | int | The new y-coordinate for the current graphics position. |
The coordinates use the current graphics coordinate system or the current viewport coordinate space if a viewport is active. After the move, connected cursor-based functions treat this new point as the current starting position.
Return Value
moveto() returns void. It does not return the previous position or confirm whether a pixel was drawn, because no drawing happens here. If you later need the current cursor point, BGI provides getx() and gety().
Code Examples
Prepare a starting point for lineto()
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(WHITE);
moveto(120, 120);
lineto(360, 120);
getch();
closegraph();
return 0;
}
The visible part is the line drawn by lineto(). The moveto() call only establishes where that line should begin.
Start separated shape paths cleanly
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(LIGHTCYAN);
moveto(140, 260);
lineto(240, 180);
lineto(340, 260);
moveto(420, 150);
lineto(520, 150);
lineto(520, 250);
getch();
closegraph();
return 0;
}
The second moveto() prevents the next connected segment from continuing the first shape. This is a clean way to begin a new path elsewhere on the screen.
Mix absolute and relative path drawing
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(YELLOW);
moveto(200, 200);
linerel(80, 0);
linerel(0, 80);
linerel(-80, 0);
linerel(0, -80);
getch();
closegraph();
return 0;
}
This example shows how moveto() can place the cursor exactly once, after which relative segments build the rest of the shape.
Common Mistakes
Expecting visible output from moveto()
moveto() changes state only. It does not draw a point, line, or marker on the screen.
Confusing it with line()
line() draws between two explicit endpoints. moveto() only changes the internal current position used by later path functions.
Forgetting coordinate context in viewports
Inside a viewport, the apparent origin can shift. A move to (10, 10) may refer to a local corner inside that viewport, not the full screen origin.
Try it online
Run the examples and temporarily remove the moveto() calls to see how connected drawing paths behave differently.