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 8693149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:28:55+00:00 2026-06-13T00:28:55+00:00

This one must be a silly question, but I am not able to understand

  • 0

This one must be a silly question, but I am not able to understand why this happens

int main()
{
    int i=20;
    int *p=&i;
    cout<<"old p="<<p<<endl;
    *(++p) = 10;
    cout<<"p="<<p<<endl;

}

In this code I get the output as:
old p=0x22ff08
p=oxa

Why is the value of the pointer getting changed to 10(0xa) instead of incrementing the earlier address and assign 10 to that location?

  • 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-13T00:28:56+00:00Added an answer on June 13, 2026 at 12:28 am

    Why is the value of the pointer getting changed to 10(0xa) instead of incrementing the earlier address and assign 10 to that location?

    To what location? There is no such location. p was pointing to one int, not an array of ints. The pointer that results from such increment does not point to a location that you can perform indirection on. Attempting to do so as this code does has undefined behaviour, meaning absolutely anything can happen. The compiler is free to do whatever it pleases, because there are no requirements on what need to happen. Don’t do it.

    In your particular experiment, it appears that the two variables were located next to each other, and when incremented, the variable p ended up pointing to itself, and then assigned 10, which is A in hexadecimal. There is no guarantee that this will happen again when you compile with a different compiler version or compiler options, or even if you make seemingly innocent changes to the code. Don’t do it.

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

Sidebar

Related Questions

This must be a very stupid question, but how does one recode with Xuggler?
Well, this must be a silly one. Here below is a can-not-be-simpler code in
I'm afraid that this is a very silly question, but I must be missing
I know this question is silly. But as per our intelligent Client request, I
This may be a silly question, due to missing some understanding of java but
My question seems really silly. But I really headache with this question. For example
Somehow I feel really silly to ask this question, but I just spent 2
There are questions LIKE this one, but they are not similar enough to my
This one has been stumping me for a while. But I'm no expert. This
I know this question is a bit silly. I am a Java Programmer that

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.