The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Types, Operators and Expression Code Example!
Discuss Types, Operators and Expression Code Example! in the C Programming forum on Dev Shed. Types, Operators and Expression Code Example! C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 25th, 2012, 03:01 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 17
Time spent in forums: 3 h 40 m 13 sec
Reputation Power: 0
|
|
|
Types, Operators and Expression Code Example!
Hey guys,
I have this code and the output for this code is:
integer0 = 3, integer1 =5,integer2 = 9, integer3 =6.
I wanna understand why the integer1 is equal 5 and integer2 equal 9. The other makes sense.
Thank you very much.
g Code:
Original
- g Code |
|
|
|
#include <stdio.h>
#define ITERATIONS 3
void main(void)
{
int integer0 = 0, integer1 = 1, integer2 = 2, integer3 =3;
for(;integer2++, integer0 < ITERATIONS ;)
integer1 = (integer0++, ++integers2, integer3++);
printf("integer0 = %1d, integer1 =%1d,"
"integer2 = %1d, integer3 =%1d.\n", integer0, integer1, integer2, integer3);
}
|

November 25th, 2012, 04:35 PM
|
 |
Contributing User
|
|
|
|
|
If I recall correctly, the comma operator has lowest precedence, evaluates from left to right, and has the value of the right hand expression.
Also, the value of the post-increment operator is the value of the variable. The variable changes afterward.
Therefor the final value of integer1 will be 1 less than the final value of integer3, which you say you understand.
integer2 starts at 2. You then increment it twice per cycle over three cycles bring it to 8. Bring your smart computer to the condition statement:
integer2++, integer0 < ITERATIONS;
integer2 increments once again, to 9, and integer0 is no longer less than ITERATIONS, so the condition is 0 and the loop terminates.
Don't write code like this.
__________________
[code] Code tags[/code] are essential for python code!
|

November 25th, 2012, 05:01 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 17
Time spent in forums: 3 h 40 m 13 sec
Reputation Power: 0
|
|
Thank you b49P23TIvg!
But why integer2 inkrements once again, to 9 and integer1 to 5.
Why integer2 increments once again, to 9? And integer3 to 6?? 
|

November 25th, 2012, 05:15 PM
|
 |
Contributing User
|
|
|
|
|
My explanation has caused you to doubt your understanding of integer3, which you previously claimed to understand. Furthermore, you still don't understand integer1 and integer2. I quit.
|

November 25th, 2012, 05:26 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 17
Time spent in forums: 3 h 40 m 13 sec
Reputation Power: 0
|
|
|
You are right! I will try it tomorrow again...Thanx...!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|