I want to know that we have a code which is given below:
int i = 2, j = i; if (Convert.ToBoolean((i | j & 5) & (j - 25 * 1))) Console.WriteLine(1); else Console.WriteLine(0);
The Output of the program is 0 Please let anyone explain me that how it produces the output 0 in brief.
Sam HobbsPosted Dec 6, 2011, 2:06 PM
First, do you know how to use the debugger? Are you familiar with breakpoints? Are you familiar with the debugging commands Step Into, Step Over and Step Out? If not then try to find articles about that or ask here.
Next, break up the code into something such as:
int t1, t2, t3;
t1 = i | j & 5;
t2 = j - 25 * 1;
t3 = t1 & t2;
bool b = Convert.ToBoolean(t3);
if (b)
Console.WriteLine(1);
else
Console.WriteLine(0);
Then put a breakpoint somewhere in there such as on the "t1 = i | j & 5;" line. Then debug. First use "Debug | Windows | Locals" to show the Locals window. You probably want to pin the window to keep it showing. Note that we cannot show the Locals debugging window unless we are debugging so you won't find it if you are not debugging. Then single-step (Step Over) each line and watch what happens to the data. Note that the data will be shown using a red font if the data has changed.
I hope you learn a lot using these techniques many times in the future.
VulpesPosted Dec 6, 2011, 1:24 PM