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

Why zero tolerance on nudity in space?

What is the most fuel efficient way out of the Solar System?

Do authors have to be politically correct in article-writing?

Which communication protocol is used in AdLib sound card?

How can I get my players to come to the game session after agreeing to a date?

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

Is Krishna the only avatar among dashavatara who had more than one wife?

Cookies - Should the toggles be on?

Is it possible to grant users sftp access without shell access? If yes, how is it implemented?

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

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

Absorbing damage with Planeswalker

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

How can my powered armor quickly replace its ceramic plates?

Why publish a research paper when a blog post or a lecture slide can have more citation count than a journal paper?

Consequences of lack of rigour

What sets the resolution of an analog resistive sensor?

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

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

Is there any risk in sharing info about technologies and products we use with a supplier?

Is there a Linux system call to create a “view” of a range of a file?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

How do I draw the dashed lines as shown in this figure

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?



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


















20














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






    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









    20














    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




























      20














      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


























        20












        20








        20







        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
















            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














            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














            • 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








            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


















            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

            Paper upload error, “Upload failed: The top margin is 0.715 in on page 3, which is below the required...

            Emraan Hashmi Filmografia | Linki zewnętrzne | Menu nawigacyjneGulshan GroverGulshan...

            How can I write this formula?newline and italics added with leqWhy does widehat behave differently if I...