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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:57:19+00:00 2026-06-08T10:57:19+00:00

I am quite happy using the C++ style casting operators within my code but

  • 0

I am quite happy using the C++ style casting operators within my code but I cannot say that I truly understand what goes on behind the scenes. I am basically wondering what actually is happening to the pointer during the following short process:

class A {};
class B : public A {};
class C : public B {};

A* pC = new C();

B* b = static_cast<B*>(pC);    // Is the value of pC changed by the cast?
C* c = static_cast<B*>(pC);    // Is the value of pC changed by the cast?
B* b2 = static_cast<B*>(c)     // Is the value of c now equal to the value of b2?

I realise that the object pointed to by pC is always of type C but after the first cast is made, I assume that the address stored in b is no longer equal to that of pC. But if the cast changes the value of pC my assumption is wrong. In a nutshell, can the cast operators actually change the address of the pointer they cast? This may seem a pretty facile question, but in my mind the picture is just not clear of how objects with an inheritance hierarchy are stored within memory and how the pointers get manipulated via the casts.

In my head the value of pC remains unchanged no matter how many casts are performed on it but is this thinking correct?

  • 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-08T10:57:21+00:00Added an answer on June 8, 2026 at 10:57 am

    The casted pointer can point to another location. In case of multiple inheritance for example. Good read

    The original pointer will be preserved

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

Sidebar

Related Questions

I'm using Googles excellent Code Prettify and I'm quite happy with it. But: Does
I'm using mercurial queues quite alot, and I'm really happy with them, but there
I'm currently using MongoDB to record application logs, and while I'm quite happy with
I've been using CodeIgniter for some quite time, and I've been extremely happy with
I've been using RVM for quite some time now and have been very happy
I've been using font-squirrel for quite sometime and was really happy with its generator
I have been using MVC for a while now and am quite happy with
I've been using Janrain engange for quite a while and have been quite happy
I'm using the manual document class of Sphinx and I'm quite happy with how
I am using cancan, devise, and omniauth in a rails app. I'm quite happy

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.