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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:44:57+00:00 2026-05-17T16:44:57+00:00

Possible Duplicate: Modified a constant in c const int z = 420; const void

  • 0

Possible Duplicate:
Modified a constant in c

const int z = 420;
const void *v;
v = &z;

printf("\n%d | %d",z,*(int *)v);
//420 | 420

printf("\n%d | %d",*(char *)&z,*(char *)v); //0th-Bit same value
//-92 | -92

printf("\n%d | %d",*((char *)&z+1),*((char *)v+1) );    //1st-Bit same value    
//1 | 1

/***********************************************/
*((char *)&z+1) = 21;   //I change value for the 1st-Bit
                            //see v is not touched here.

printf("\n%d | %d -(note)-successfully corrupted (z+1) and change reflected in (v+1)",*((char *)&z+1),*((char *)v+1) );
//21 | 21
//yes  change is reflected in v after corruption of z

/****************the problem******************/

printf("\n%d | %d",z,*(int *)v);    //but now value of v is courrupt...while that of z is same
//420 | 5540
printf("\n%u | %u",&z,v);               //same address different values?
//1310548 | 1310548


/*************additional info*******************/

printf("\n%d | %d",*(&(*(&z+1))-1),*(int *)v);
//5540 | 5540

printf("\n%u | %u",(&(*(&z+1))-1),v);
//1310548 | 1310548

1>

void pointer pointing to “z”

when dereferenced gives corrupted value

but when z is used directly it gives original value.

so same address is holding 2 different values

2>

when z is subjected to an identity pointer transformation

(i.e. increment and decrement back)

z will now output the corrupted value!

but z when subjected to normal or no transformations

like “*(&z)” will still give the original value.

  • 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-17T16:44:57+00:00Added an answer on May 17, 2026 at 4:44 pm

    Stop asking this question 😉

    If it helps, you can assume that the compiler has taken code like this:

    const int z = 420;
    ...
    printf("%d\n", z);
    

    And replaced it with:

    const int z = 420;
    ...
    printf("%d\n", 420);
    

    That’s not guaranteed, you can’t rely on it, but it’s the kind of thing compilers do, and it would account for what you’re seeing.

    You also take the address of z, but the compiler won’t/can’t necessarily track the use of that pointer, and replace all accesses through it in the same way. That’s a much harder job than just recognising that the symbol z refers to a const object. So when you invalidly modified that const object, one of the ways in which undefined behavior has manifested is the inconsistencies you’re seeing.

    If you want to know what your compiler has actually done, and you won’t follow James’ advice, then you’re out of luck. Nobody here knows for sure exactly what your compiler has done. Nobody even knows what compiler you’re using. Different compilers do different things.

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

Sidebar

Related Questions

Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: Using Git how do I find modified files between local and remote
Possible Duplicate: How do I find the last modified file in a directory in
Possible Duplicate: How to prevent an ASP.NET application restarting when the web.config is modified?
Possible Duplicate: What does map(&:name) mean in Ruby? I was watching a railscast and
Possible Duplicate: How do you give a C# Auto-Property a default value? Hi all:
Possible Duplicate: What does template <unsigned int N> mean? Hi ! Are non-type template
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be

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.