This code crashed my PC D:

I just wrote this simple code to output memory addresses and my Pc crashed, why is that?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

int MemAddress(int MA1, int MA2)
{
    MA1 = 7999;
    MA2 = 8432;
}

int main()
{
    int MA1, MA2;
    
    MemAddress(MA1, MA2);
    
    cout << &MA1 << endl;
    cout << &MA2 << endl;
}


Im running windows 8 using code blocks does anyone know what just happened?
If getting the addresses of two variables on the stack crashes your system, there is something horribly wrong.

Line 5: You're not passing by reference. This function does nothing.

Line 9: For that matter, this code shouldn't even compile because MemAddress is supposed to return an int, but ultimately it never does.

-Albatross
How did it crash? With a blue screen and all?

However (not related to your question directly), your MemAddress function doesn't do anything, maybe you meant to write int MemAddress(int& MA1, int& MA2) instead? (note the &, which mean that the variables are references instead of copies).

Could you try casting those two values to int, to see if it stops crashing? (I'm not shure what cout does with a raw pointer.)

EDIT: Are you shure it is actually crashing, not just closing down the console straight after execution?
Last edited on
no it gave me a blue screen with a frowny face and it said something along the lines of "Windows has crashed, we are collecting crash information and your pc will restart in xx %"

this screen here

http://i45.tinypic.com/ip8j75.jpg
Last edited on
Topic archived. No new replies allowed.