Skip to content
Related Articles

Related Articles

Improve Article
Debugging in Turbo C++
  • Difficulty Level : Medium
  • Last Updated : 15 Mar, 2021

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.



Select Watch

  Step 2: You’ll be able to see a panel named Watch at the bottom of your IDE.

Watch panel

  Step 3: Similarly, from the Window menu we’ll select Output and Message and then click on Tile for a better view.

Output and Message window

Step 4: Go to Debug, then under Watches choose Add Watch (or Ctrl+F7).  

Add Watch

Step 5: A dialog box will appear on your screen saying “Enter Expression to add as Watch”. Enter ‘a’.



Enter Watch Expression

Step 6: Watch panel will show the result of adding ‘a’ as a watch expression.

Watch expression 'a'

Step 7: Follow Step 5 again and Enter ‘b’.

Watch expression 'b'

Step 8: Go to Run Option and Click Trace Into (or F7).

Trace Into

Step 9: You will notice void main() being highlighted. This means our program has started running.

Code is executing

Step 10: Go to the Run menu and Click Step Over (or F8) to proceed to the next step.

Step over



Step 11: Step over proceeds to the next statement.

Step over#2

Step 12: Press F8 to execute the next statement.

Step over#3

Step 13: Step Over (F8).

Step over#4

Step 14: Proceed to Next Step (F8).

Step over#5Step 15: Enter the 2 numbers in the console.

Enter 2 numbers

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.

Output

Step 17: Press F8.

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.

Press F8

Step 19: Press F8 to check what is the next step. You’ll be able to see the Output screen now.

Output

Step 20: Press F8 to check what will happen next.

Debugging ends

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.

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :