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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:31:38+00:00 2026-06-08T22:31:38+00:00

I observe some weird behavior today , the code is as follow : The

  • 0

I observe some weird behavior today , the code is as follow :

The Code :

#include <iostream>

struct text
{
    char c;
};

int main(void)
{
    text experim = {'b'};
    char * Cptr = &(experim.c);

    std::cout << "The Value \t: " << *Cptr << std::endl ;
    std::cout << "The Address \t: " << Cptr << std::endl  ; //Print weird stuff

    std::cout << "\n\n";

    *Cptr = 'z';   //Attempt to change the value

    std::cout << "The New Value \t: " << *Cptr <<std::endl ;
    std::cout << "The Address \t: " << Cptr << std::endl ; //Weird address again

    return 0;
}

The Question :


1.) The only question I have is why cout theAddress for the above code would come out some weird value ?

2.)Why I can still change the value of the member c by dereferenncing the pointer which has weird address ?

Thank you.

  • 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-08T22:31:39+00:00Added an answer on June 8, 2026 at 10:31 pm

    Consider fixing the code like this:

    std::cout << "The Address \t: " << (void *)Cptr << std::endl ;
    

    There’s a std::ostream& operator<< (std::ostream& out, const char* s ); that takes a char* so you have to cast to void* to print an address, not a string it “points” to

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

Sidebar

Related Questions

Interfacing with legacy code, and I've got something like this: Event.observe(some_form, 'submit', [some anonymous
I have InApp purchasing setup in my app. I am having some weird behavior
I was having some weird Glib behavior, searched the internet a little and found
I was trying to observe how some of the top browser game makers are
I'm using dm-observer to observe my dm models, and I need to perform some
I have some third party code, that invokes double.ToString() . My problem, is that
I'm writing some MVC JavaScript code using Prototype. The problem is that when I
I'm observing some strange behavior with a local variable within a nested for loop
Something really weird is happening to my Rails app. For some strange reason, jQuery
In Android FileObserver i am getting some weird event numbers like (1073742080, 1073742336) when

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.