- #1
fluidistic
Gold Member
- 3,953
- 265
Sorry I don't have the codes right now.
In C plus plus, when I declare an int, but don't assign any value to it, a space in memory is allocated for it. I can define a pointer and check its adress in hexadecimal, so far so good. I can run this program over and over and usually the int is allocated nearly at the same spot in memory,(I am guessing in the RAM). I made some plots, and sometimes it can vary greatly but overall the values don't differ that much, it's a ''big'' number like 194344563 or something like that. As far as I understand, this number heavily depends on the OS and compiler, so if I could save those addresses in memory, I could possibly determine the OS and or compiler on which the program is running.
Now here's the thing. If I use a loop to allocate (freeing or not memory won't change the following behavior), the first value is as usual, i.e. the big int, but.then the next values are completely different. Sometimes I get 0's, other times negative ints. So the behavior is totally different than if I had ran the program N times. I couldn't find a way to create a single Cpp program that would be equivalent.to execute N times the simple cpp code. ChatGPT was also at a loss.
Now here's another strange.thing. If I allocate an array of dimension N of ints instead of a single int, then the 1st entry of this.array is the usual big int, but then some other values are 0's (usually the 3rd to 6th values might be 0's but not always), and this kills me.
How is that possible that several ints are allocated at the 0 memory entry? Why 0? And much more importantly, how can several ints fit in the same memory spot? That doesn't make any sense?
In C plus plus, when I declare an int, but don't assign any value to it, a space in memory is allocated for it. I can define a pointer and check its adress in hexadecimal, so far so good. I can run this program over and over and usually the int is allocated nearly at the same spot in memory,(I am guessing in the RAM). I made some plots, and sometimes it can vary greatly but overall the values don't differ that much, it's a ''big'' number like 194344563 or something like that. As far as I understand, this number heavily depends on the OS and compiler, so if I could save those addresses in memory, I could possibly determine the OS and or compiler on which the program is running.
Now here's the thing. If I use a loop to allocate (freeing or not memory won't change the following behavior), the first value is as usual, i.e. the big int, but.then the next values are completely different. Sometimes I get 0's, other times negative ints. So the behavior is totally different than if I had ran the program N times. I couldn't find a way to create a single Cpp program that would be equivalent.to execute N times the simple cpp code. ChatGPT was also at a loss.
Now here's another strange.thing. If I allocate an array of dimension N of ints instead of a single int, then the 1st entry of this.array is the usual big int, but then some other values are 0's (usually the 3rd to 6th values might be 0's but not always), and this kills me.
How is that possible that several ints are allocated at the 0 memory entry? Why 0? And much more importantly, how can several ints fit in the same memory spot? That doesn't make any sense?