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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:59:39+00:00 2026-05-21T19:59:39+00:00

A pointer is a variable that points to a location in memory. int *pointer1;

  • 0

A pointer is a variable that points to a location in memory.

int *pointer1;
int *pointer2 = pointer1;

Let’s say that both variables are pointing to memory location

0xA

Then I perform

pointer2++;

Now, pointer2 points to

0xB

Because both addresses point to the same place, I fully expect pointer1 to point to

0xB

But it does not. pointer1 still points to 0xA.

How is this possible? Does the pointer have another address to specify which pointer it actually is? If yes, what is this second address called?

  • 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-05-21T19:59:40+00:00Added an answer on May 21, 2026 at 7:59 pm

    You are confusing the value stored in the pointer with the value to which the pointer points.

    The two pointers, per se, are completely independent, they just happen to point to the same memory location. When you write

    pointer2++;
    

    you are incrementing the value stored in pointer2 (i.e. address to which it points), not the value stored at the pointed location; being pointer and pointer2 independent variables, there’s no reason why also pointer should change its value.


    More graphically:

    int var=42;
    int * ptr1 = &var;
    int * ptr2 = ptr2;
    

    Supposing that var is stored at memory location 0x10, we’ll have this situation:

    +----------+
    |          |  0x00
    +----------+
    |          |  0x04
    +----------+                      
    |          |  0x08               +------------+
    +----------+              +------| ptr1: 0x10 |
    |          |  0x0C        |      +------------+
    +----------+              |      +------------+
    | var: 42  |  0x10   <----+------| ptr2: 0x10 |
    +----------+                     +------------+
    |          |  0x14      
    +----------+
    |          |  0x18
    +----------+
    |          |
    

    Now we increment ptr2

    ptr2++;
    

    (due to pointer arithmetic the stored address gets incremented of sizeof(int), that here we assume being 4)

    +----------+
    |          |  0x00
    +----------+
    |          |  0x04
    +----------+                      
    |          |  0x08               +------------+
    +----------+              +------| ptr1: 0x10 |
    |          |  0x0C        |      +------------+
    +----------+              |      +------------+
    | var: 42  |  0x10   <----+   +--| ptr2: 0x14 |
    +----------+                  |  +------------+
    |          |  0x14   <--------+
    +----------+
    |          |  0x18
    +----------+
    |          |
    

    Now ptr2 points to 0x14 (what’s there is not important in this example); ptr1 is left untouched pointing to 0x10.

    (naturally both ptr1 and ptr2 have an address where they are stored, as any other variable; this is not shown in the diagrams for clarity)

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

Sidebar

Related Questions

In examples on the web, calls to CreateThread typically pass a pointer to a
I'm working on a game engine in C++ using Lua for NPC behaviour. I
I'm looking at some code at the moment which has been ported and is
So I've checked my pointers and I'm really not sure what's going wrong here.
I'm new to VBA but I'm trying to get a DYMO LabelWriter to work
I am programming in C. Considering the following Code. My structure is defined as:
QUESTION ANSWERED IN COMMENTS Because of my reputation, I can't answer it in the
I am having one small problem with my code. I am sending a POST
Is there anyway to create a dynamically retrievable method which somehow monitors an object's
I am having trouble getting my pointers to work correctly. In my main file

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.