C and C++ debugging

Online GDB Debugger for C and C++

Find bugs in C and C++ programs without installing anything. Set breakpoints, step through your code line by line, and watch variables and the call stack change, all with real GDB running behind the editor.

How to debug C or C++ online with GDB

  1. Open the C++ editor or the C editor and make sure Server mode is selected in the runtime menu.
  2. Write or paste your program, or open one of the examples below.
  3. Click beside a line number to set a breakpoint. You can set as many as you need.
  4. Select Debug. The program compiles with debug information and pauses on the first breakpoint it reaches.
  5. Look at the Variables and Call Stack panels, then use Continue, Step Over, Step Into or Step Out to move through the code.
  6. Select Stop debugging when you have found the problem.

What you can do

  • BreakpointsPause exactly where a value starts to go wrong instead of adding print statements everywhere.
  • Step through codeStep over a line, into a function call or back out of it, and see which line runs next.
  • Inspect variablesSee local variables and their current values every time the program pauses.
  • Call stackFollow how the program reached the current line, one function call at a time.
  • Multiple filesWork with headers and several source files, the way real C and C++ projects are organized.
  • AI helpStuck on an error? Ask the AI to explain the code or suggest a fix, right in the editor.

Try it: find the bug in this C++ program

This program should print an average of 77.75, but it prints 77. Set a breakpoint on the double average line, select Debug and look at total and scores.size(). Both are integers, so the division drops the decimals. Changing it to static_cast<double>(total) / scores.size() fixes it.

main.cpp
main.cpp
#include <iostream>
#include <vector>

int main() {
    std::vector<int> scores = {72, 85, 90, 64};
    int total = 0;
    for (int score : scores) {
        total += score;
    }
    // Expected 77.75, but this prints 77. Set a breakpoint here and inspect total.
    double average = total / scores.size();
    std::cout << "Average: " << average << std::endl;
    return 0;
}

The same bug in C

In C the cause is the same: total / count divides two integers. Debug it, then fix it with (double)total / count.

main.c
main.c
#include <stdio.h>

int main(void) {
    int scores[] = {72, 85, 90, 64};
    int count = 4, total = 0;
    for (int i = 0; i < count; i++) {
        total += scores[i];
    }
    /* Expected 77.75, but this prints 77.00. Set a breakpoint here and inspect total. */
    double average = total / count;
    printf("Average: %.2f\n", average);
    return 0;
}

Learn C and C++ step by step

Debugging is easier when you know what the code should do. These lessons explain the topics where bugs hide most often, with C and C++ code you can run.

Frequently asked questions

Is this a real GDB debugger?

Yes. In Server mode your C or C++ program is compiled with debug information and runs under GDB on our server. The editor shows the current line, the variables and the call stack while you step.

Do I need to install GCC or GDB?

No. Everything runs in your browser and on our server, so you can debug from any computer without a compiler, a debugger or an IDE.

How do I set a breakpoint?

Click beside a line number in the editor. Then select Debug, and the program pauses when it reaches that line.

Can I debug programs with several files?

Yes. The editor supports projects with several files, so you can debug the same kind of program you would build locally.

Is it free?

Yes. Compiling, running and debugging are free and do not need an account. Signing in lets you save workspaces and share code.