0

I try to change the value of a variable (first_var) from an already known Address. i.e I already know what its address is, though I dont have a pointer to it..

I wrote the code below in an attempt to change its value from the address thats already known, which is 0x61fdfc, without getting its pointer by writing something like: &first_var

This is the code:

#include <iostream>

int main(){
    int first_var = 10;
    long *addr = 0x61fdfc;
    std::string s;
    *addr = 20;
    std::cin >> s;
    return 0;
}

Though when I compile it(By GCC compiler), I get that error:

.cpp: In function 'int main()': editor.cpp:5:15: error: invalid conversion from 'int' to 'long int*' [-fpermissive] long *addr = 0x61fdfc;

How do I fix that error, and how do I get it working as expected?

0 Answers0