What is WATCH in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is WATCH in C++?

I have seen a lot of WATCH(someVariable) within a C++ code. Does anyone have an idea about what it is?

24th Feb 2017, 2:03 AM
Kleber Leal
Kleber Leal - avatar
4 Answers
+ 2
for using watch first you have to get into debugging moe.For that begin by using the “Step into” command. In Visual Studio 2005 Express, go to the debug menu and choose “Step Into”, or press F11. If you are using a different IDE, find the “Step Into” command in the menus and select it. When you do this, two things should happen. First, because our application is a console program, a console output window should open. It will be empty because we haven’t output anything yet. Second, you should see some kind of marker appear to the left of the opening brace of main. In Visual Studio 2005 Express, this marker is a yellow arrow. If you are using a different IDE, you should see something that serves the same purpose.
24th Feb 2017, 3:14 AM
gaurav kulkarni
gaurav kulkarni - avatar
+ 2
This arrow marker indicates that the line being pointed to will be executed next.
24th Feb 2017, 3:18 AM
gaurav kulkarni
gaurav kulkarni - avatar
+ 2
Watching a variable is the process of inspecting the value of a variable while the program is executing in debug mode. Most debuggers provide several ways to do this. Let’s take a look at a sample program: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include "stdafx.h" #include <iostream> int main() {     int x =1;     std::cout << x << " ";       x = x + 1;     std::cout << x << " ";       x = x + 2;     std::cout << x << " ";       x = x + 4;     std::cout << x << " ";       return 0; } This is a pretty straightforward sample program -- it prints the numbers 1, 2, 4, and 8. First, use the “Run to cursor” command to debug to the first std::cout << x << " "; line:  At this point, the variable x has already been created and initialized with the value 1, so when we examine the value of x, we should expect to see the value 1. The easiest way to examine the value of a simple variable like x is to hover your mouse over the variable x. Most modern debuggers support this method of inspecting simple variables, and it is the most straightforward way to do so.  Note that you can hover over any variable x, not just the one on the current line:  If you’re using Visual Studio, you can also use QuickWatch. Highlight the variable name x with your mouse, and then choose “QuickWatch” from the right-click menu.  This will pull up a subwindow containing the current value of the variable:  Go ahead and close QuickWatch if you opened it. Now let’s watch this variable change as we step through the program. First, choose “Step over” twice, so the next line to be executed is the second std::cout << x << " "; line:  The variable x should now have value 2. Inspect it and make sure that it does!
24th Feb 2017, 3:33 AM
gaurav kulkarni
gaurav kulkarni - avatar
+ 1
it was so big explanation so copied last part from google.hope you understood it.
24th Feb 2017, 3:34 AM
gaurav kulkarni
gaurav kulkarni - avatar