0% found this document useful (0 votes)
6 views13 pages

Content

Uploaded by

Ayushi Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views13 pages

Content

Uploaded by

Ayushi Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Name: Dipansha Nimkar Date: 02/06/2023

Section / Roll No: I_02

7. Aim: Debugging in Turbo C++ and Dev C++

• Turbo C++
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.

1
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.

2
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

3
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’.

4
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.

5
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.

6
Step 12: Press F8 to execute the next statement.

Step 13: Step Over (F8).

7
Step 14: Proceed to Next Step (F8).

Step 15: Enter the 2 numbers in the console.

8
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.

9
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.

10
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.

• Dev C++

Dev-C++ is an integrated development environment (IDE) for C and C++ programming


languages. While it offers basic debugging capabilities, it's important to note that Dev-C++ is

11
no longer actively maintained and may not provide all the advanced debugging features
available in modern IDEs like Visual Studio or Code:Blocks.

• To debug your program using Dev-C++, you can follow these steps:

1.Open your project in Dev-C++: Launch Dev-C++ and open the project that contains the
code you want to debug.

2.Enable debugging symbols: Ensure that your program is compiled with debugging symbols
enabled. This step is crucial as it allows the debugger to associate the source code with the
compiled binary and provide meaningful information during debugging. To enable debugging
symbols, go to "Project" -> "Project Options" -> "Compiler" and check the "Produce
debugging information (-g)" option.

3.Set breakpoints: Breakpoints are markers that tell the debugger to pause program execution
at specific locations in your code. You can set breakpoints by clicking on the left margin of
the code editor, next to the line where you want the program to pause. A red dot will appear
to indicate the breakpoint.

4.Start debugging: To begin the debugging process, go to the "Debug" menu and select "Start
Debugging" or press F8. Alternatively, you can click the "Debug" toolbar button with a bug
icon.

5.Observe program execution: Once the debugging session starts, the program will run until it
encounters a breakpoint. When a breakpoint is hit, the program will pause, allowing you to
inspect the state of variables and step through the code.

6.Inspect variables and watch expressions: While the program is paused at a breakpoint, you
can examine the values of variables to understand their current state. You can hover over
variables in the code editor to see their values or add variables or expressions to the "Watch"
window. To add a variable to the "Watch" window, right-click in the code editor, select "Add
Watch" or "Quick Watch," and enter the variable or expression you want to monitor.

7.Step through the code: To navigate through the code during debugging, Dev-C++ provides
several options:
o Step Into (F7): This option allows you to step into function calls. If the current line of
code contains a function call, pressing F7 will take you inside the function definition.
o Step Over (F8): Use this option to execute the current line of code and proceed to the
next line. If the current line contains a function call, F8 will execute the entire
12
function without stepping into it. o Step Out (Ctrl+F8): If you have stepped into a
function using F7 and want to quickly return to the calling code, press Ctrl+F8. It
will execute the remaining lines of the current function and return to the caller. o
Continue (F9): When you want to continue program execution from the current
breakpoint until the next breakpoint or the end of the program, press F9.

8.Analyze program behavior: As you step through the code, observe the variable values and
program flow to identify any unexpected behavior or logical errors. Utilize the variable values
displayed in the code editor or the "Watch" window to track changes and ensure they match
your expectations.

9.Repeat steps 5-8: Continue stepping through the code, setting breakpoints, and examining
variable values until you locate and understand the issue causing the problem.
By following these steps, you can effectively debug your code using Dev-C++.

Conclusion:

Here, We successfully explore the debugging steps in Turbo C++ and Dev C++.

Debugging is help to remove the errors and it’s check line by line.

13

You might also like