Difference between i++ and (i)++ in CWhat is the difference between #include <filename> and #include...

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

Finding a logistic regression model which can achieve zero error on a training set training data for a binary classification problem with two features

Alien invasion to probe us, why?

Can we harness gravitational potential energy?

Removing disk while game is suspended

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Play Zip, Zap, Zop

How would an AI self awareness kill switch work?

What does it mean for a caliber to be flat shooting?

How can I remove (non-trivial) duplicates from a VCF file?

Can you tell from a blurry photo if focus was too close or too far?

What is the purpose of easy combat scenarios that don't need resource expenditure?

How does Leonard in "Memento" remember reading and writing?

Consequences of lack of rigour

What incentives do banks have to gather up loans into pools (backed by Ginnie Mae)and selling them?

What is a good reason for every spaceship to carry a weapon on board?

Slow While Loop, Query Improvment Assistance

Is using an 'empty' metaphor considered bad style?

How to tell if a BJT is PNP or NPN by looking at the circuit?

Avoid page break between paragraphs

Dilemma of explaining to interviewer that he is the reason for declining second interview

Absorbing damage with Planeswalker

Why did Democrats in the Senate oppose the Born-Alive Abortion Survivors Protection Act (2019 S.130)?

What are "industrial chops"?



Difference between i++ and (i)++ in C


What is the difference between #include <filename> and #include “filename”?What is the difference between ++i and i++?What is the difference between const int*, const int * const, and int const *?What is the difference between a definition and a declaration?Difference between malloc and calloc?Improve INSERT-per-second performance of SQLite?Difference between static and shared libraries?How do I achieve the theoretical maximum of 4 FLOPs per cycle?Does C make a difference between compiling and executing a program?Space as a token its impact on evaluation of binary or unary operator













6















int i = 3;
int j = (i)++;


vs



int i = 3;
int j = i ++;


Though both of the above examples store 3 in j, is there a difference between how the above two cases are evaluated?



Since i is an int, do the () cause the first case to be evaluated as an expression, which would be equivalent to incrementing an rvalue? Or is it undefined behaviour and just happens to store 3 in j?



Or am I overthinking it and its just a simple postfix?










share|improve this question




















  • 2





    Seemingly arbitrary usage of parentheses is common in macro definitions. Where they do make a big difference, you'd like the error message you get. Well, usually.

    – Hans Passant
    4 hours ago
















6















int i = 3;
int j = (i)++;


vs



int i = 3;
int j = i ++;


Though both of the above examples store 3 in j, is there a difference between how the above two cases are evaluated?



Since i is an int, do the () cause the first case to be evaluated as an expression, which would be equivalent to incrementing an rvalue? Or is it undefined behaviour and just happens to store 3 in j?



Or am I overthinking it and its just a simple postfix?










share|improve this question




















  • 2





    Seemingly arbitrary usage of parentheses is common in macro definitions. Where they do make a big difference, you'd like the error message you get. Well, usually.

    – Hans Passant
    4 hours ago














6












6








6








int i = 3;
int j = (i)++;


vs



int i = 3;
int j = i ++;


Though both of the above examples store 3 in j, is there a difference between how the above two cases are evaluated?



Since i is an int, do the () cause the first case to be evaluated as an expression, which would be equivalent to incrementing an rvalue? Or is it undefined behaviour and just happens to store 3 in j?



Or am I overthinking it and its just a simple postfix?










share|improve this question
















int i = 3;
int j = (i)++;


vs



int i = 3;
int j = i ++;


Though both of the above examples store 3 in j, is there a difference between how the above two cases are evaluated?



Since i is an int, do the () cause the first case to be evaluated as an expression, which would be equivalent to incrementing an rvalue? Or is it undefined behaviour and just happens to store 3 in j?



Or am I overthinking it and its just a simple postfix?







c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 hours ago









Richard Chambers

10k24167




10k24167










asked 5 hours ago









Polaris000Polaris000

131412




131412








  • 2





    Seemingly arbitrary usage of parentheses is common in macro definitions. Where they do make a big difference, you'd like the error message you get. Well, usually.

    – Hans Passant
    4 hours ago














  • 2





    Seemingly arbitrary usage of parentheses is common in macro definitions. Where they do make a big difference, you'd like the error message you get. Well, usually.

    – Hans Passant
    4 hours ago








2




2





Seemingly arbitrary usage of parentheses is common in macro definitions. Where they do make a big difference, you'd like the error message you get. Well, usually.

– Hans Passant
4 hours ago





Seemingly arbitrary usage of parentheses is common in macro definitions. Where they do make a big difference, you'd like the error message you get. Well, usually.

– Hans Passant
4 hours ago












2 Answers
2






active

oldest

votes


















21














i++ and (i)++ behave identically. C 2018 6.5.1 5 says:




A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.







share|improve this answer































    3














    In your simple example of i++ versus (i)++, there is no difference, as noted in Eric Postpischil's answer.



    However, this difference is actually meaningful if you are dereferencing a pointer variable with the * operator and using the increment operator; there is a difference between *p++ and (*p)++.



    The former statement dereferences the pointer and then increments the pointer itself; the latter statement dereferences the pointer then increments the dereferenced value.






    share|improve this answer





















    • 1





      @downvoter: reason?

      – Govind Parmar
      5 hours ago






    • 1





      @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

      – Govind Parmar
      5 hours ago











    • An attempt to make information available through denormalization instead of structuration is a controversial way.

      – SerG
      5 hours ago








    • 1





      "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

      – zwol
      5 hours ago











    • Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

      – n0rd
      2 mins ago











    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',
    autoActivateHeartbeat: false,
    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%2f54908480%2fdifference-between-i-and-i-in-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    21














    i++ and (i)++ behave identically. C 2018 6.5.1 5 says:




    A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.







    share|improve this answer




























      21














      i++ and (i)++ behave identically. C 2018 6.5.1 5 says:




      A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.







      share|improve this answer


























        21












        21








        21







        i++ and (i)++ behave identically. C 2018 6.5.1 5 says:




        A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.







        share|improve this answer













        i++ and (i)++ behave identically. C 2018 6.5.1 5 says:




        A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 5 hours ago









        Eric PostpischilEric Postpischil

        77.3k881164




        77.3k881164

























            3














            In your simple example of i++ versus (i)++, there is no difference, as noted in Eric Postpischil's answer.



            However, this difference is actually meaningful if you are dereferencing a pointer variable with the * operator and using the increment operator; there is a difference between *p++ and (*p)++.



            The former statement dereferences the pointer and then increments the pointer itself; the latter statement dereferences the pointer then increments the dereferenced value.






            share|improve this answer





















            • 1





              @downvoter: reason?

              – Govind Parmar
              5 hours ago






            • 1





              @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

              – Govind Parmar
              5 hours ago











            • An attempt to make information available through denormalization instead of structuration is a controversial way.

              – SerG
              5 hours ago








            • 1





              "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

              – zwol
              5 hours ago











            • Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

              – n0rd
              2 mins ago
















            3














            In your simple example of i++ versus (i)++, there is no difference, as noted in Eric Postpischil's answer.



            However, this difference is actually meaningful if you are dereferencing a pointer variable with the * operator and using the increment operator; there is a difference between *p++ and (*p)++.



            The former statement dereferences the pointer and then increments the pointer itself; the latter statement dereferences the pointer then increments the dereferenced value.






            share|improve this answer





















            • 1





              @downvoter: reason?

              – Govind Parmar
              5 hours ago






            • 1





              @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

              – Govind Parmar
              5 hours ago











            • An attempt to make information available through denormalization instead of structuration is a controversial way.

              – SerG
              5 hours ago








            • 1





              "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

              – zwol
              5 hours ago











            • Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

              – n0rd
              2 mins ago














            3












            3








            3







            In your simple example of i++ versus (i)++, there is no difference, as noted in Eric Postpischil's answer.



            However, this difference is actually meaningful if you are dereferencing a pointer variable with the * operator and using the increment operator; there is a difference between *p++ and (*p)++.



            The former statement dereferences the pointer and then increments the pointer itself; the latter statement dereferences the pointer then increments the dereferenced value.






            share|improve this answer















            In your simple example of i++ versus (i)++, there is no difference, as noted in Eric Postpischil's answer.



            However, this difference is actually meaningful if you are dereferencing a pointer variable with the * operator and using the increment operator; there is a difference between *p++ and (*p)++.



            The former statement dereferences the pointer and then increments the pointer itself; the latter statement dereferences the pointer then increments the dereferenced value.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 4 hours ago

























            answered 5 hours ago









            Govind ParmarGovind Parmar

            11.8k53361




            11.8k53361








            • 1





              @downvoter: reason?

              – Govind Parmar
              5 hours ago






            • 1





              @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

              – Govind Parmar
              5 hours ago











            • An attempt to make information available through denormalization instead of structuration is a controversial way.

              – SerG
              5 hours ago








            • 1





              "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

              – zwol
              5 hours ago











            • Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

              – n0rd
              2 mins ago














            • 1





              @downvoter: reason?

              – Govind Parmar
              5 hours ago






            • 1





              @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

              – Govind Parmar
              5 hours ago











            • An attempt to make information available through denormalization instead of structuration is a controversial way.

              – SerG
              5 hours ago








            • 1





              "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

              – zwol
              5 hours ago











            • Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

              – n0rd
              2 mins ago








            1




            1





            @downvoter: reason?

            – Govind Parmar
            5 hours ago





            @downvoter: reason?

            – Govind Parmar
            5 hours ago




            1




            1





            @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

            – Govind Parmar
            5 hours ago





            @SerG In my experience this particular nuance leads to a very common error by beginners, so I thought it was worth mentioning here.

            – Govind Parmar
            5 hours ago













            An attempt to make information available through denormalization instead of structuration is a controversial way.

            – SerG
            5 hours ago







            An attempt to make information available through denormalization instead of structuration is a controversial way.

            – SerG
            5 hours ago






            1




            1





            "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

            – zwol
            5 hours ago





            "increments the pointer and then dereferences it" may be confusing, since you're using postincrement -- I would suggest "dereferences the pointer and then increments the pointer".

            – zwol
            5 hours ago













            Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

            – n0rd
            2 mins ago





            Your answer: a) acknowledges that question has already been answered; b) goes on a tangent about the case that question didn't mention.

            – n0rd
            2 mins ago


















            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54908480%2fdifference-between-i-and-i-in-c%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

            Benedict Cumberbatch Contingut Inicis Debut professional Premis Filmografia bàsica Premis i...

            Monticle de plataforma Contingut Est de Nord Amèrica Interpretacions Altres cultures Vegeu...

            Escacs Janus Enllaços externs Menú de navegacióEscacs JanusJanusschachBrainKing.comChessV