As i saw the simple problem of increment and decrement has become an issue of 
debate in this group and now we are started to blame on each others 
knowledge. Well I am not saying that who is wrong.
And i don't want to have a debate on this matter.

The Clear and Final Answer of the above term is that:



Consider the following statement:
x = j * j++;

The C language does not specify which multiplication operand
is to be evaluated first. 

The C language does not have any law to execute such a statements.
One compiler may evaluate the left operand
first, while another evaluates the right operand first. The results
are different in the two cases. If j equals 5, and the left operand
is evaluated first, the expression will be interpreted as
x = 5 *  5;   /* x is assigned 25 */
If the right operand is evaluated first, the expression becomes
x = 6 * 5;   /* x is assigned 30 */



As there is no algorithm provided by c language to execute such statements 
therefore different compiler programmers and developers use different 
algorithms to execute such statements.
They may take it from left to right or from right to left 

or in other extreme condition the program may be 

crashed.

Statements such as this one are not portable and should be
avoided. The side effect problem also crops up in function calls
because the C language does not guarantee the order in which arguments
are evaluated. For example, the function call
f(a, a++)
is not portable because compilers are free to evaluate the
arguments in any order they choose.
To prevent side effect bugs, follow this rule: If you use
a side effect operator in an expression, do not use the affected
variable anywhere else in the expression. The ambiguous expression
above, for instance, can be made unambiguous by breaking it into
two assignments:
x = j * j;
++j;

so the answer of the original problem for having different output is that
c language does not have any law or algorithm for compilers to execute these 
kind of statements.
And thats why different compiler designers develop
different algorithms for this.
And that why the result is different.

The same compiler if giving a answer may give another answer next time 
according to its algo on which it is designed.
or The same compiler may give each time the same result.
That's all depend on compiler and because of the lack of a Unique Law in c 
language.
So i hope now the problem has been resolved.

Be happy friends !!



      

[Non-text portions of this message have been removed]

Reply via email to