Debugging is a process in which the programmers detect and remove the existing or potential errors/bugs in their programs. It is an excellent practice for writing an effective code. Now, Turbo C++ provides a variety of useful features for the sake of its community. Some options that play an important role in our debugging are Watch and Trace. Let’s understand these concepts by taking the following program:
Example: Write a program to check if two numbers are Equal or Not
Now go through the undermentioned steps to get a clear idea of how to debug:
Step 1: Go to Window Menu and click Watch under it.
Step 2: You’ll be able to see a panel named Watch at the bottom of your IDE.
Step 3: Similarly, from the Window menu we’ll select Output and Message and then click on Tile for a better view.
Step 4: Go to Debug, then under Watches choose Add Watch (or Ctrl+F7).
Step 5: A dialog box will appear on your screen saying “Enter Expression to add as Watch”. Enter ‘a’.
Step 6: Watch panel will show the result of adding ‘a’ as a watch expression.
Step 7: Follow Step 5 again and Enter ‘b’.
Step 8: Go to Run Option and Click Trace Into (or F7).
Step 9: You will notice void main() being highlighted. This means our program has started running.
Step 10: Go to the Run menu and Click Step Over (or F8) to proceed to the next step.
Step 11: Step over proceeds to the next statement.
Step 12: Press F8 to execute the next statement.
Step 13: Step Over (F8).
Step 14: Proceed to Next Step (F8).
Step 15: Enter the 2 numbers in the console.
Step 16: Take a look at the watch and output panels. After getting the input from the user, the compiler overwrites the values in the variables.
Step 17: Press F8.
Remember since our if the condition is True the compiler shouldn’t check the else statement.
Step 18: Press F8 to proceed to the next step.
Step 19: Press F8 to check what is the next step. You’ll be able to see the Output screen now.
Step 20: Press F8 to check what will happen next.
Notice the closing bracket is highlighted now, which means the program has ended. If F8 is pressed again the program will run over again from the first step.