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

  • Home
  • SEARCH
  • 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 3227820
In Process

The Archive Base Latest Questions

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

const int z = 420; printf(\n%d | %d,z ,*(&(*(&z+1))-1) ); // O/P:420 | 420

  • 0
const int z = 420;

printf("\n%d | %d",z ,*(&(*(&z+1))-1) );
// O/P:420 | 420

printf("\n%u | %u",&z,(&(*(&z+1))-1) );             //address
// O/P:1310548  | 1310548

*((char *)&z+1) = 21;       //I change value for the 1st-Bit
                                    //corrupting constant

 printf("\n%d | %d",z ,*(&(*(&z+1))-1) );
//the complex(not really) expression evaluates to z
// O/P:420| 5540

printf("\n%u | %u",&z ,(&(*(&z+1))-1) );                
//the complex(not really) expression evaluates to &z
// O/P:1310548 | 1310548

Why is this happening?

it seems that I have successfully modified constant in C

by modify I mean I have changed the bits in the constants address range

as the “complex(not really) unity/identity expression”
changes value after corruption.

but the z remains same. Why?

how come same address have different values when de-referenced. ?

PS: u can use any identity expression

eg.printf("%d",*(int*)((char*)&(*((char*)&z+1))-1));

[edit]

ok let me re-phrase it:

z = 420

&z = 1310548

*(&(*(&z+1))-1) = 420

(&(*(&z+1))-1)  = 1310548

now I do to corrupt the constant

*((char *)&z+1) = 21;

NOW AFTER CORRUPTING:

z = 420     // NO CHANGE EVEN THOUGH I have corrupted

&z = 1310548

*(&(*(&z+1))-1) = z = 5540    // THE CHANGE

(&(*(&z+1))-1)  = &z = 1310548

WHY?

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

    There’s not a while lot of mystery here. By using casts to tell the compiler that what you’re changing isn’t const qualified, you’re causing undefined behavior:

    6.7.3/5 “Type qualifiers” (C99):

    If an attempt is made to modify an object defined with a const-qualified type through use
    of an lvalue with non-const-qualified type, the behavior is undefined.

    Some implementations might have placed the variable z in read only memory and you’d either get no apparent change or some sort of access violation.

    In any case, undefined behavior means all bets are off – in your case you’re able to see the apparent modification of a const value.

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

Sidebar

Related Questions

My Code const int howmany = 5046; char buffer[howmany]; asm(lea buffer,%esi); //Get the address
const int SIZE = 3; const char val[SIZE] = {'3', 'z', '7'}; const string&
Possible Duplicate: Modified a constant in c const int z = 420; const void
void DoWork(int n); void DoWork(const int &n); What's the difference?
I'm a bit confused what happened in the following code: const int e =
const int t=5; char buf[t+5]; When I compile this gives error in C but
I have the following code : const int k=1; int *p=const_cast<int *>( &k); cout<<k
EDIT: void print(const int *v, const int size) { FILE *fpIn; fpIn = fopen(char-array.txt,
What is the difference between these (in Const manner): const int getNum(int &a, int
const int &ra=3; As I know, making ra const will extends the lifetime of

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.