What is the result of i == (i = 2)?











up vote
7
down vote

favorite
2












Run the following code:



// In Java, output #####
public static void main(String args) {
int i = 1;

if(i == (i = 2)) {
System.out.println("@@@@@");
} else {
System.out.println("#####");
}
}


But:



// In C, output @@@@@,I did test on Clion(GCC 7.3) and Visual Studio 2017
int main(int argc, char *argv) {
int i = 1;

if(i == (i = 2)) {
printf("@@@@@");
} else {
printf("#####");
}

return 0;
}


The motivation for asking this question comes from the following code:



// The code is from the JDK 11 - java.util.concurrent.atomic.AtomicInteger
// I am curious about the behavior of the variable prev.
public final int getAndUpdate(IntUnaryOperator updateFunction) {
int prev = get(), next = 0;
for (boolean haveNext = false;;) {
if (!haveNext)
next = updateFunction.applyAsInt(prev);
if (weakCompareAndSetVolatile(prev, next))
return prev;
haveNext = (prev == (prev = get()));
}
}


So, how to explain the above two different execution modes?










share|improve this question






















  • One explains the two different execution modes by first noting that those are two entirely different languages. They happen to share some syntax, but that's where the similarities end.
    – StoryTeller
    38 mins ago















up vote
7
down vote

favorite
2












Run the following code:



// In Java, output #####
public static void main(String args) {
int i = 1;

if(i == (i = 2)) {
System.out.println("@@@@@");
} else {
System.out.println("#####");
}
}


But:



// In C, output @@@@@,I did test on Clion(GCC 7.3) and Visual Studio 2017
int main(int argc, char *argv) {
int i = 1;

if(i == (i = 2)) {
printf("@@@@@");
} else {
printf("#####");
}

return 0;
}


The motivation for asking this question comes from the following code:



// The code is from the JDK 11 - java.util.concurrent.atomic.AtomicInteger
// I am curious about the behavior of the variable prev.
public final int getAndUpdate(IntUnaryOperator updateFunction) {
int prev = get(), next = 0;
for (boolean haveNext = false;;) {
if (!haveNext)
next = updateFunction.applyAsInt(prev);
if (weakCompareAndSetVolatile(prev, next))
return prev;
haveNext = (prev == (prev = get()));
}
}


So, how to explain the above two different execution modes?










share|improve this question






















  • One explains the two different execution modes by first noting that those are two entirely different languages. They happen to share some syntax, but that's where the similarities end.
    – StoryTeller
    38 mins ago













up vote
7
down vote

favorite
2









up vote
7
down vote

favorite
2






2





Run the following code:



// In Java, output #####
public static void main(String args) {
int i = 1;

if(i == (i = 2)) {
System.out.println("@@@@@");
} else {
System.out.println("#####");
}
}


But:



// In C, output @@@@@,I did test on Clion(GCC 7.3) and Visual Studio 2017
int main(int argc, char *argv) {
int i = 1;

if(i == (i = 2)) {
printf("@@@@@");
} else {
printf("#####");
}

return 0;
}


The motivation for asking this question comes from the following code:



// The code is from the JDK 11 - java.util.concurrent.atomic.AtomicInteger
// I am curious about the behavior of the variable prev.
public final int getAndUpdate(IntUnaryOperator updateFunction) {
int prev = get(), next = 0;
for (boolean haveNext = false;;) {
if (!haveNext)
next = updateFunction.applyAsInt(prev);
if (weakCompareAndSetVolatile(prev, next))
return prev;
haveNext = (prev == (prev = get()));
}
}


So, how to explain the above two different execution modes?










share|improve this question













Run the following code:



// In Java, output #####
public static void main(String args) {
int i = 1;

if(i == (i = 2)) {
System.out.println("@@@@@");
} else {
System.out.println("#####");
}
}


But:



// In C, output @@@@@,I did test on Clion(GCC 7.3) and Visual Studio 2017
int main(int argc, char *argv) {
int i = 1;

if(i == (i = 2)) {
printf("@@@@@");
} else {
printf("#####");
}

return 0;
}


The motivation for asking this question comes from the following code:



// The code is from the JDK 11 - java.util.concurrent.atomic.AtomicInteger
// I am curious about the behavior of the variable prev.
public final int getAndUpdate(IntUnaryOperator updateFunction) {
int prev = get(), next = 0;
for (boolean haveNext = false;;) {
if (!haveNext)
next = updateFunction.applyAsInt(prev);
if (weakCompareAndSetVolatile(prev, next))
return prev;
haveNext = (prev == (prev = get()));
}
}


So, how to explain the above two different execution modes?







java c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









kangjianwei

26728




26728












  • One explains the two different execution modes by first noting that those are two entirely different languages. They happen to share some syntax, but that's where the similarities end.
    – StoryTeller
    38 mins ago


















  • One explains the two different execution modes by first noting that those are two entirely different languages. They happen to share some syntax, but that's where the similarities end.
    – StoryTeller
    38 mins ago
















One explains the two different execution modes by first noting that those are two entirely different languages. They happen to share some syntax, but that's where the similarities end.
– StoryTeller
38 mins ago




One explains the two different execution modes by first noting that those are two entirely different languages. They happen to share some syntax, but that's where the similarities end.
– StoryTeller
38 mins ago












4 Answers
4






active

oldest

votes

















up vote
10
down vote













The behaviour of a C program that executes the expression i == (i = 2) is undefined.



It comes from C11 6.5p22:





  1. If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84)




The i on the left-hand side of == is a value computation on the value of scalar object i and the right-hand side i = 2 has a side effect of assigning the value 2 to i. The LHS and RHS of == are unsequenced w.r.t. each other. Hence the entire program is meaningless in C.



Compile with gcc -Wall and GCC will spit out:



unsequenced.c:5:16: warning: operation on ‘i’ may be undefined [-Wsequence-point]
if(i == (i = 2)) {
~~~^~~~




Unlike C, Java guarantees the evaluation order for operands (left-to-right), therefore



haveNext = (prev == (prev = get()));


is correct in Java. The value of LHS is determined strictly before the evaluation of the side effect on the RHS occurs.



In C you have to write this as something like



newPrev = get();
haveNext = (prev == newPrev);
prev = newPrev;





share|improve this answer























  • Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
    – Some Name
    1 hour ago










  • @SomeName of course it is specified somewhere in the standard. :D
    – Antti Haapala
    1 hour ago










  • So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
    – Some Name
    1 hour ago










  • @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
    – Antti Haapala
    48 mins ago












  • @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
    – Antti Haapala
    42 mins ago


















up vote
4
down vote













The Java Language Specification (§15.7) states:




The Java programming language guarantees that the operands of operators appear
to be evaluated in a specific evaluation order, namely, from left to right.




The specification (§15.21.1) also states that:




The value produced by the == operator is true if the value of the left-hand
operand is equal to the value of the right-hand operand; otherwise, the result is
false.




Therefore in Java, the if-statement at runtime would look like the following, which obviously evaluates to false:



if (1 == 2) {

}


In C, it is simply undefined (see Antti's answer).






share|improve this answer






























    up vote
    1
    down vote













    In C, the behavior of i == (i = 2) is undefined because it attempts to both update an object and use that object’s value in a computation without an intervening sequence point. The result will vary based on the compiler, compiler settings, even the surrounding code.






    share|improve this answer




























      up vote
      -2
      down vote













       if(i == (i = 2))


      in java language , the result of following statement will be 1 and but in c Language the result will be 2 and else section will run. the difference is in java first the condition will be checked and after that i value will change but in c first the value will change and after that condition will be checked and it's because of executive grades in java language






      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53577739%2fwhat-is-the-result-of-i-i-2%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        10
        down vote













        The behaviour of a C program that executes the expression i == (i = 2) is undefined.



        It comes from C11 6.5p22:





        1. If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84)




        The i on the left-hand side of == is a value computation on the value of scalar object i and the right-hand side i = 2 has a side effect of assigning the value 2 to i. The LHS and RHS of == are unsequenced w.r.t. each other. Hence the entire program is meaningless in C.



        Compile with gcc -Wall and GCC will spit out:



        unsequenced.c:5:16: warning: operation on ‘i’ may be undefined [-Wsequence-point]
        if(i == (i = 2)) {
        ~~~^~~~




        Unlike C, Java guarantees the evaluation order for operands (left-to-right), therefore



        haveNext = (prev == (prev = get()));


        is correct in Java. The value of LHS is determined strictly before the evaluation of the side effect on the RHS occurs.



        In C you have to write this as something like



        newPrev = get();
        haveNext = (prev == newPrev);
        prev = newPrev;





        share|improve this answer























        • Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
          – Some Name
          1 hour ago










        • @SomeName of course it is specified somewhere in the standard. :D
          – Antti Haapala
          1 hour ago










        • So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
          – Some Name
          1 hour ago










        • @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
          – Antti Haapala
          48 mins ago












        • @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
          – Antti Haapala
          42 mins ago















        up vote
        10
        down vote













        The behaviour of a C program that executes the expression i == (i = 2) is undefined.



        It comes from C11 6.5p22:





        1. If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84)




        The i on the left-hand side of == is a value computation on the value of scalar object i and the right-hand side i = 2 has a side effect of assigning the value 2 to i. The LHS and RHS of == are unsequenced w.r.t. each other. Hence the entire program is meaningless in C.



        Compile with gcc -Wall and GCC will spit out:



        unsequenced.c:5:16: warning: operation on ‘i’ may be undefined [-Wsequence-point]
        if(i == (i = 2)) {
        ~~~^~~~




        Unlike C, Java guarantees the evaluation order for operands (left-to-right), therefore



        haveNext = (prev == (prev = get()));


        is correct in Java. The value of LHS is determined strictly before the evaluation of the side effect on the RHS occurs.



        In C you have to write this as something like



        newPrev = get();
        haveNext = (prev == newPrev);
        prev = newPrev;





        share|improve this answer























        • Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
          – Some Name
          1 hour ago










        • @SomeName of course it is specified somewhere in the standard. :D
          – Antti Haapala
          1 hour ago










        • So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
          – Some Name
          1 hour ago










        • @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
          – Antti Haapala
          48 mins ago












        • @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
          – Antti Haapala
          42 mins ago













        up vote
        10
        down vote










        up vote
        10
        down vote









        The behaviour of a C program that executes the expression i == (i = 2) is undefined.



        It comes from C11 6.5p22:





        1. If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84)




        The i on the left-hand side of == is a value computation on the value of scalar object i and the right-hand side i = 2 has a side effect of assigning the value 2 to i. The LHS and RHS of == are unsequenced w.r.t. each other. Hence the entire program is meaningless in C.



        Compile with gcc -Wall and GCC will spit out:



        unsequenced.c:5:16: warning: operation on ‘i’ may be undefined [-Wsequence-point]
        if(i == (i = 2)) {
        ~~~^~~~




        Unlike C, Java guarantees the evaluation order for operands (left-to-right), therefore



        haveNext = (prev == (prev = get()));


        is correct in Java. The value of LHS is determined strictly before the evaluation of the side effect on the RHS occurs.



        In C you have to write this as something like



        newPrev = get();
        haveNext = (prev == newPrev);
        prev = newPrev;





        share|improve this answer














        The behaviour of a C program that executes the expression i == (i = 2) is undefined.



        It comes from C11 6.5p22:





        1. If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.84)




        The i on the left-hand side of == is a value computation on the value of scalar object i and the right-hand side i = 2 has a side effect of assigning the value 2 to i. The LHS and RHS of == are unsequenced w.r.t. each other. Hence the entire program is meaningless in C.



        Compile with gcc -Wall and GCC will spit out:



        unsequenced.c:5:16: warning: operation on ‘i’ may be undefined [-Wsequence-point]
        if(i == (i = 2)) {
        ~~~^~~~




        Unlike C, Java guarantees the evaluation order for operands (left-to-right), therefore



        haveNext = (prev == (prev = get()));


        is correct in Java. The value of LHS is determined strictly before the evaluation of the side effect on the RHS occurs.



        In C you have to write this as something like



        newPrev = get();
        haveNext = (prev == newPrev);
        prev = newPrev;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 42 mins ago

























        answered 1 hour ago









        Antti Haapala

        78.8k16147190




        78.8k16147190












        • Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
          – Some Name
          1 hour ago










        • @SomeName of course it is specified somewhere in the standard. :D
          – Antti Haapala
          1 hour ago










        • So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
          – Some Name
          1 hour ago










        • @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
          – Antti Haapala
          48 mins ago












        • @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
          – Antti Haapala
          42 mins ago


















        • Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
          – Some Name
          1 hour ago










        • @SomeName of course it is specified somewhere in the standard. :D
          – Antti Haapala
          1 hour ago










        • So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
          – Some Name
          1 hour ago










        • @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
          – Antti Haapala
          48 mins ago












        • @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
          – Antti Haapala
          42 mins ago
















        Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
        – Some Name
        1 hour ago




        Why is i on the LHS a value computation? Is it specified somewhere in the Standard?
        – Some Name
        1 hour ago












        @SomeName of course it is specified somewhere in the standard. :D
        – Antti Haapala
        1 hour ago




        @SomeName of course it is specified somewhere in the standard. :D
        – Antti Haapala
        1 hour ago












        So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
        – Some Name
        1 hour ago




        So how about reference? :) The only I could find was the value term defined in 3.19, but no value computation defined there.
        – Some Name
        1 hour ago












        @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
        – Antti Haapala
        48 mins ago






        @SomeName you need to infer it from way too many places in the prose :/ the footnote 84 however can be used as a shortcut. If i there was not a value of an expression then a[i++] = i; would be defined. Footnotes are not normative though.
        – Antti Haapala
        48 mins ago














        @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
        – Antti Haapala
        42 mins ago




        @SomeName 5.1.2.3p2 says "value computation of lvalue expression", which is a case here, i is an lvalue and its value need to be computed, as it is not an operand. 6.3.2.1p2 says "converted to the value stored in the designated object", but this is the one referred to by 5.1.2.3p2
        – Antti Haapala
        42 mins ago












        up vote
        4
        down vote













        The Java Language Specification (§15.7) states:




        The Java programming language guarantees that the operands of operators appear
        to be evaluated in a specific evaluation order, namely, from left to right.




        The specification (§15.21.1) also states that:




        The value produced by the == operator is true if the value of the left-hand
        operand is equal to the value of the right-hand operand; otherwise, the result is
        false.




        Therefore in Java, the if-statement at runtime would look like the following, which obviously evaluates to false:



        if (1 == 2) {

        }


        In C, it is simply undefined (see Antti's answer).






        share|improve this answer



























          up vote
          4
          down vote













          The Java Language Specification (§15.7) states:




          The Java programming language guarantees that the operands of operators appear
          to be evaluated in a specific evaluation order, namely, from left to right.




          The specification (§15.21.1) also states that:




          The value produced by the == operator is true if the value of the left-hand
          operand is equal to the value of the right-hand operand; otherwise, the result is
          false.




          Therefore in Java, the if-statement at runtime would look like the following, which obviously evaluates to false:



          if (1 == 2) {

          }


          In C, it is simply undefined (see Antti's answer).






          share|improve this answer

























            up vote
            4
            down vote










            up vote
            4
            down vote









            The Java Language Specification (§15.7) states:




            The Java programming language guarantees that the operands of operators appear
            to be evaluated in a specific evaluation order, namely, from left to right.




            The specification (§15.21.1) also states that:




            The value produced by the == operator is true if the value of the left-hand
            operand is equal to the value of the right-hand operand; otherwise, the result is
            false.




            Therefore in Java, the if-statement at runtime would look like the following, which obviously evaluates to false:



            if (1 == 2) {

            }


            In C, it is simply undefined (see Antti's answer).






            share|improve this answer














            The Java Language Specification (§15.7) states:




            The Java programming language guarantees that the operands of operators appear
            to be evaluated in a specific evaluation order, namely, from left to right.




            The specification (§15.21.1) also states that:




            The value produced by the == operator is true if the value of the left-hand
            operand is equal to the value of the right-hand operand; otherwise, the result is
            false.




            Therefore in Java, the if-statement at runtime would look like the following, which obviously evaluates to false:



            if (1 == 2) {

            }


            In C, it is simply undefined (see Antti's answer).







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 1 hour ago

























            answered 1 hour ago









            Jacob G.

            14.7k51961




            14.7k51961






















                up vote
                1
                down vote













                In C, the behavior of i == (i = 2) is undefined because it attempts to both update an object and use that object’s value in a computation without an intervening sequence point. The result will vary based on the compiler, compiler settings, even the surrounding code.






                share|improve this answer

























                  up vote
                  1
                  down vote













                  In C, the behavior of i == (i = 2) is undefined because it attempts to both update an object and use that object’s value in a computation without an intervening sequence point. The result will vary based on the compiler, compiler settings, even the surrounding code.






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    In C, the behavior of i == (i = 2) is undefined because it attempts to both update an object and use that object’s value in a computation without an intervening sequence point. The result will vary based on the compiler, compiler settings, even the surrounding code.






                    share|improve this answer












                    In C, the behavior of i == (i = 2) is undefined because it attempts to both update an object and use that object’s value in a computation without an intervening sequence point. The result will vary based on the compiler, compiler settings, even the surrounding code.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 1 hour ago









                    John Bode

                    80.6k1375149




                    80.6k1375149






















                        up vote
                        -2
                        down vote













                         if(i == (i = 2))


                        in java language , the result of following statement will be 1 and but in c Language the result will be 2 and else section will run. the difference is in java first the condition will be checked and after that i value will change but in c first the value will change and after that condition will be checked and it's because of executive grades in java language






                        share|improve this answer

























                          up vote
                          -2
                          down vote













                           if(i == (i = 2))


                          in java language , the result of following statement will be 1 and but in c Language the result will be 2 and else section will run. the difference is in java first the condition will be checked and after that i value will change but in c first the value will change and after that condition will be checked and it's because of executive grades in java language






                          share|improve this answer























                            up vote
                            -2
                            down vote










                            up vote
                            -2
                            down vote









                             if(i == (i = 2))


                            in java language , the result of following statement will be 1 and but in c Language the result will be 2 and else section will run. the difference is in java first the condition will be checked and after that i value will change but in c first the value will change and after that condition will be checked and it's because of executive grades in java language






                            share|improve this answer












                             if(i == (i = 2))


                            in java language , the result of following statement will be 1 and but in c Language the result will be 2 and else section will run. the difference is in java first the condition will be checked and after that i value will change but in c first the value will change and after that condition will be checked and it's because of executive grades in java language







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 1 hour ago









                            Nima Mohammadi

                            724




                            724






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53577739%2fwhat-is-the-result-of-i-i-2%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                404 Error Contact Form 7 ajax form submitting

                                How to know if a Active Directory user can login interactively

                                TypeError: fit_transform() missing 1 required positional argument: 'X'