Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC++/Java Codes for RHPOP3Connect Pin
codedigger2215-Sep-05 4:55
codedigger2215-Sep-05 4:55 
Questionwhat about x = x++; ? Pin
pesho293215-Sep-05 4:55
pesho293215-Sep-05 4:55 
AnswerRe: what about x = x++; ? Pin
Chris Losinger15-Sep-05 5:35
professionalChris Losinger15-Sep-05 5:35 
GeneralRe: what about x = x++; ? Pin
Anonymous15-Sep-05 6:32
Anonymous15-Sep-05 6:32 
GeneralRe: what about x = x++; ? Pin
Chris Losinger15-Sep-05 6:52
professionalChris Losinger15-Sep-05 6:52 
AnswerRe: what about x = x++; ? Pin
David Crow15-Sep-05 6:37
David Crow15-Sep-05 6:37 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 6:55
bugDanny15-Sep-05 6:55 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 7:22
David Crow15-Sep-05 7:22 
bugDanny wrote:
Hmm, being a postfix, the ++operator will complete at the end of the expression, so x = x will complete first, and then x with be incremented with ++. But maybe you explain it later in your response.

There are actually two expressions here. For VS6, the inner one (x++) is evaluated first and then the outer one (x=). The Precedence and Order of Evaluation rules dictate that postfix is always evaluated before assignment. For that matter, assignment is always evaluated last (with one exception).

Another way to look at this is the way some folks (used to) combine assignment and comparison statements into one, like:

while ((str = fgets()) != NULL)
   ...
In this example, the inner, parenthesized expression (str = fgets()) is evaluated first, and then the outer expression (str != NULL) is evaluated last. It wouldn't make much sense to compare str to NULL before it had been assigned a value from the inner expression.


bugDanny wrote:
Wait, if this is correct, and the increment occurs after the assignment, then how was you earlier statement correct, where you say the ++ operator will complete before anything is assigned? Your statements are in conflict.

My bad. I meant to reiterate that the ++ operator was being evaluated before the assignment. Sorry for the confusion.


"One must learn from the bite of the fire to leave it alone." - Native American Proverb



-- modified at 14:12 Thursday 15th September, 2005
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 7:33
bugDanny15-Sep-05 7:33 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 8:01
David Crow15-Sep-05 8:01 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 8:08
bugDanny15-Sep-05 8:08 
GeneralRe: what about x = x++; ? Pin
ky_rerun15-Sep-05 9:14
ky_rerun15-Sep-05 9:14 
GeneralRe: what about x = x++; ? Pin
David Crow15-Sep-05 9:22
David Crow15-Sep-05 9:22 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 2:51
bugDanny16-Sep-05 2:51 
AnswerRe: what about x = x++; ? Pin
Joaquín M López Muñoz15-Sep-05 6:51
Joaquín M López Muñoz15-Sep-05 6:51 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 7:23
bugDanny15-Sep-05 7:23 
GeneralRe: what about x = x++; ? Pin
Joaquín M López Muñoz16-Sep-05 5:00
Joaquín M López Muñoz16-Sep-05 5:00 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 6:45
bugDanny16-Sep-05 6:45 
GeneralRe: what about x = x++; ? Pin
Joaquín M López Muñoz16-Sep-05 7:05
Joaquín M López Muñoz16-Sep-05 7:05 
GeneralRe: what about x = x++; ? Pin
bugDanny16-Sep-05 7:41
bugDanny16-Sep-05 7:41 
AnswerRe: what about x = x++; ? Pin
Anonymous15-Sep-05 8:30
Anonymous15-Sep-05 8:30 
GeneralRe: what about x = x++; ? Pin
Anonymous15-Sep-05 8:38
Anonymous15-Sep-05 8:38 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 8:57
bugDanny15-Sep-05 8:57 
GeneralRe: what about x = x++; ? Pin
Chris Losinger15-Sep-05 8:59
professionalChris Losinger15-Sep-05 8:59 
GeneralRe: what about x = x++; ? Pin
bugDanny15-Sep-05 9:05
bugDanny15-Sep-05 9:05 

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.