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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:08:14+00:00 2026-05-27T20:08:14+00:00

#include<stdio.h> int main() { const int sum=100; int *p=(int *)&sum; *p=101; printf(%d, %d,*p,sum); return

  • 0
#include<stdio.h>

int main()
{
       const int sum=100;
        int *p=(int *)&sum;

        *p=101; 


        printf("%d, %d",*p,sum);
        return 0;
}

/*

output

101, 101

*/

p points to a constant integer variable, then why/how does *p manage to change the value of sum?

  • 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-27T20:08:15+00:00Added an answer on May 27, 2026 at 8:08 pm

    It’s undefined behavior – it’s a bug in the code. The fact that the code ‘appears to work’ is meaningless. The compiler is allowed to make it so your program crashes, or it’s allowed to let the program do something nonsensical (such as change the value of something that’s supposed to be const). Or do something else altogether. It’s meaningless to ‘reason’ about the behavior, since there is no requirement on the behavior.

    Note that if the code is compiled as C++ you’ll get an error since C++ won’t implicitly cast away const. Hopefully, even when compiled as C you’ll get a warning.

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

Sidebar

Related Questions

#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
#include <stdio.h> int main() { float a = 1234.5f; printf(%d\n, a); return 0; }
#include<stdio.h> int main() { printf(He %c llo,65); } Output: He A llo #include<stdio.h> int
#include<stdio.h> int main() { int a,b; a=a+b; printf(%d,a); return 0; } what should be
Check out this code #include<stdio.h> int main() { const int a=7; int *p=&a; (*p)++;
Consider this program: #include <stdio.h> int main() { printf(%s\n, __FILE__); return 0; } Depending
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
#include <stdio.h> int main() { const int a = 12; int *p; p =
I wrote a small Hello World app. #include <stdio.h> int main(int argc, const char

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.