A long time ago, 5 years, I made a simple C++ program that would allow you to enter a number and it would use an array to browse through the computers memory. Not change it, just take a look at the values stored inside. It worked. I'm brushing up on C++ now, I've barely made anything in these past 4 years, and I don't remember the source code. Anyways, I made this program, I never really understood pointers very well:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include "stdafx.h"
#include <iostream>
using namespace System;
void main() {
int myarray[1];
int *integer, count, memory;
for (count = 0; count != 10; count+=1) {
std::cout << "Enter a memory location: \n ";
std::cin >> memory;
*integer = memory;
std::cout << myarray[*integer]; /*I just realized while writing up this post that using a pointer to index a array indice doesn't do what I wanted. Its supposed to just go out of the arrays range.*/
}
return;
}
|
When I run this an enter something into the variable memory, I get a rather serious looking error that says I may be corrupting memory. Sounds pretty bad if you ask me. Should I try to use an array to browse the memory? By using an array, I mean using index out of range to sift through the memory.
Can this error hurt my computer? Is it permanent? Will windows fix it? Will restarting windows fix it?
I'm going to try using an array instead of a pointer, and not run this program again...
Edit: I edited the program to use an array and variable, and its not giving me that error. Can you tell me why the numbers I get out of the memory are so huge and random? I would expect something simlple like 2000, or 100, but none of these make any sense!
Another edit: I don't think you can tell a pointer what it should point to can you? like &i = 25?