Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8100593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:46:12+00:00 2026-06-05T22:46:12+00:00

Assume p is a integer pointer and i is an integer: *p++ gives an

  • 0

Assume p is a integer pointer and i is an integer:

*p++ gives an integer value corresponding to p.

i++ gives an integer value incremented by 1

Since by behavior, both the above yields integer, ++*p++ and ++i++ shouldn’t have same error reported? But why ++*p++ works while ++i++ gives compiler error?

int main()
{
int a[10] = {0};

int *p = (int*)&a;
int i = 0;

// printf("%d", ++i++); -- FAILS error: lvalue required as increment operand   
printf("%d\n", ++*p++ ); // Prints 1
return 0;
}

EDIT

++i++ is decomposed as following:

i++
++(result)

This is exactly where I am confused :
In the same way we can decompose ++*p++ as

*p++ 
++(result).

*p++ returns a value (rvalue) , not a pointer. So why the difference ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:46:14+00:00Added an answer on June 5, 2026 at 10:46 pm

    The result of post-increment is an rvalue. You’re not allowed to modify it. ++i++ attempts to modify that rvalue, which the compiler rejects.

    p++ produces an rvalue, but it’s of pointer type. You’re not allowed to modify it, but you are allowed to dereference it. *p++ dereferences that rvalue. This gives you the value it points at, as an lvalue. The pre-increment then modifies the lvalue it points at, not the rvalue that was produced by the post-increment.

    Edit: I should probably also add one more point: even if ++i++ was allowed by the compiler, the result would be undefined behavior, because it attempts to modify i twice without an intervening sequence point. In the case of ++*p++, that doesn’t happen either — the post increment modifies the pointer itself, while the pre-increment modifies what the pointer pointed at (before it was incremented). Since we’re modifying two entirely different locations, the result in not undefined behavior.

    If you wanted to badly enough, you could still get undefined behavior by initializing the pointer to point at itself, in which case both increments would attempt to modify the pointer. The committee didn’t work very hard at preventing this, probably because only the truly pedantic would be at all likely to even think of such an insane thing.

    Bottom line: in this case, the compiler is mostly trying to protect you from yourself, though you can still shoot yourself in the foot if you try hard enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume we have an integer 'x' and 'n' possible values that 'x' can be
Assume I have a budget of $10 (any integer) and I want to distribute
assume i have integer variables a,b and c. c = a + b; or
I have this code : int flags = some integer value; compte.actif = !Convert.ToBoolean(flags
Lets assume i have a function that takes 32bit integer in, and returns random
assume i have to store few integer numbers like 1024 or 512 or 10240
Assume we have a user table to be partitioned by user id as integer
Assume the field data type is varchar When i add a integer in it,
Assume that we have multiple arrays of integers. You can consider each array as
I have a set of N items, which are sets of integers, let's assume

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.