Printf Debugging: Explained for Beginners

  • Thread starter Thread starter chmate
  • Start date Start date
  • Tags Tags
    Debugging
AI Thread 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top