October 27, 2024
Chicago 12, Melborne City, USA
C++

Problems with constant int and pointer indicating it


The book that I’m studying now taught me like expected but repl.it shows result as an output

Please let me know why this result came out.
Thank you.

**Output**
MAX=999
MAX=999


**Expected**
MAX=999
MAX=666
#include <stdio.h>
#pragma warning(disable : 4996)

int main(void) {
    const int MAX = 999;
    int *ptr;
    ptr=(int*)&MAX;
    *ptr=666;
    printf("MAX=%d\n",MAX);
    return 0;
}



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video