Printf Debugging: Explained for Beginners

  • Thread starter Thread starter chmate
  • Start date Start date
  • Tags Tags
    Debugging
Click For Summary
Printf debugging involves inserting print statements in code to track the program's internal behavior and monitor important calculations. This method, sometimes referred to as "instrumentation," is particularly useful when traditional debugging tools are unavailable or when working with a serial interface. While effective for gaining insights into code execution, it is considered a slower debugging approach compared to using dedicated debugging software, which allows for direct code examination. For those new to programming, understanding and implementing printf debugging can provide valuable experience in tracking down issues, even though investing in a debugger may offer a more efficient solution.
chmate
Messages
37
Reaction score
0
Hi there,

I'm noob at programming. Can anyone explain me why we need printf debugging, how to implement it, and for what is used it?

Thank you
 
Technology news on Phys.org
"Printf debugging" is a rather dumb term to describe placing print statements throughout your code, often printing the value of important intermediate calculations, so that you can observe the program's internal behavior.

- Warren
 
"instrumentation" may a better, more all-inclusive term.
 
Instrumentation is normally used in situations where you can't get at the code with a debugger but you have accesses to some kind of serial interface to a terminal. Then the printf statements send messages to the terminal. You just enter the printf statements in the code, compile and then look at the results. Enter more printfs, compile and look at the results. It is a SLOW way to debug.

In most cases, it is easier to simply use an inexpensive debugger and look at the code directly. You can get a Visual Basic or Visual C++ debugger for around $100 these days.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 31 ·
2
Replies
31
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
Replies
1
Views
2K