| | |
Problem with precedence in C
![]() |
I am having this problem with precedence of operators. Its with the increment and decrement operators.
this evaluates to 6 instead of 7 . Why does this happen. It would be of great help to me.
Thanks,
comwizz
C Syntax (Toggle Plain Text)
int i,j=1; i=(j++)+(++j)+(j++);
Thanks,
comwizz
•
•
•
•
Originally Posted by comwizz
I am having this problem with precedence of operators. Its with the increment and decrement operators.
this evaluates to 6 instead of 7 . Why does this happen. It would be of great help to me.C Syntax (Toggle Plain Text)
int i,j=1; i=(j++)+(++j)+(j++);
Thanks,
comwizz
All my posts may be redistributed under the GNU Free Documentation License.
•
•
•
•
Originally Posted by Rashakil Fol
It looks like you're expecting the expression (j++)+(++j)+(j++) to be evaluated from left to right. The C standard does not require this. Because you are modifying your variable j more than once in the same expression, the behavior is undefined.
Thanks,
comwizz.
•
•
•
•
Originally Posted by comwizz
Even if we evaluate from the right for j=1 the expression will be evaluated like 1 + 3 + 3 and will still turn out to be 7.
(k = j++ + j++) might be treated equally as either k = j + j; j += 2; or k = j; j += 1; k += j; j += 1;You need to separate your expression into multiple statements. For another example: Is
y[i] = ++i; equivalent to y[i] = i; i += 1; or y[i + 1] = i; i += 1;? All my posts may be redistributed under the GNU Free Documentation License.
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Problem With "Where" with boolean type (MS SQL)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Connection Problems (Networking Hardware Configuration)
Other Threads in the C Forum
- Previous Thread: Linked List Retrieve Method
- Next Thread: A couple of ?s on algorithms. Help Plz
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






