Click here to Skip to main content
15,887,283 members
Home / Discussions / C#
   

C#

 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 5:34
mvaKenneth Haugland28-Apr-13 5:34 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 5:41
mveOriginalGriff28-Apr-13 5:41 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 6:14
mvaKenneth Haugland28-Apr-13 6:14 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 5:28
harold aptroot28-Apr-13 5:28 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 5:34
mvaKenneth Haugland28-Apr-13 5:34 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 21:33
N8tiv28-Apr-13 21:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Keld Ølykke28-Apr-13 20:34
Keld Ølykke28-Apr-13 20:34 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:11
N8tiv28-Apr-13 22:11 
Okay, just to recap… I'm going to show the example they gave me first… Then tell you how I understand what you guys have been trying to help me with.
Then I will post my exercise towards the end and try to explain how I came up with my answer doing it in my head before running the program and printing it to the console window.

<pre lang="c#">
// Example 3-2.cs
// Increment and Decrement
using System;
class ArithmeticOperators
{
public static void Main()
{
int x = 10;
int y = 100;
int z = y-- + x;
Console.WriteLine(z); // result = 110
Console.WriteLine(y); // result = 99 — The value of y after
// decrementing
z = --z + x;
Console.WriteLine(z); // result = 119
}
}
</pre>
So, we print out the variable z… Like it says, the result is 110. Okay, easy enough.
Just in my mind, the variable y automagically becomes 99.
Anyway, you guys have explained to me that the variable y takes on the new value after evaluating the expression.
Semi-sort of easy enough.

Using this as somewhat of a template for my exercise is probably what threw me off.

In the exercise, I got the first expression done in my head correctly. Meaning it matched what the console window printed out.

The second expression, using the example above.

I also thought the variable y would become the new value after evaluating the first expression.
That's why in my head, I came up with 121… The console window printed out 111.

Drill 3-1
Start with the following assignments:
int x = 10;
int y = 100;
int z = y;
Then write a C# program to compute and display the values of the
variables y and z after executing these expressions:
y = y++ + x;
z = ++z + x;

<a href="http://www.widmarkrob.com">My Online Journey</a>
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 22:20
harold aptroot28-Apr-13 22:20 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:35
N8tiv28-Apr-13 22:35 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 22:42
harold aptroot28-Apr-13 22:42 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:54
N8tiv28-Apr-13 22:54 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 23:39
mveOriginalGriff28-Apr-13 23:39 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 23:47
N8tiv28-Apr-13 23:47 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff29-Apr-13 0:33
mveOriginalGriff29-Apr-13 0:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv30-Apr-13 19:04
N8tiv30-Apr-13 19:04 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff30-Apr-13 21:57
mveOriginalGriff30-Apr-13 21:57 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv30-Apr-13 23:02
N8tiv30-Apr-13 23:02 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff30-Apr-13 23:36
mveOriginalGriff30-Apr-13 23:36 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 22:31
N8tiv4-May-13 22:31 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 22:50
mveOriginalGriff4-May-13 22:50 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 23:02
N8tiv4-May-13 23:02 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 23:14
mveOriginalGriff4-May-13 23:14 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 23:48
N8tiv4-May-13 23:48 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 23:58
mveOriginalGriff4-May-13 23:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.