I find GDB (Gnu DeBugger) to be the best tool for c/c++. It's probably already installed on your system if you have gcc installed.
To use it, make sure you compile your program with the -g
flag:
gcc -g myprog.c -o myprog
And then launch the debugger with
gdb ./myprog
Here are some basic commands to get you going:
b lineno - set a break point at line 'lineno'
b srcfile:lineno - set a break point in source file 'srcfile' at line 'lineno'
r - run the program
s - step through the next line of code
c - continue execution up to the next breakpoint
p varname - print the value of the variable 'varname'