PDA

View Full Version : A VERY VERY WEIRD pure c++ problem



Zander87
27th November 2012, 23:26
Hello All, since this evening I have a very weird problem: I have a problem when executing this code
Speicherzugriffsfehler (Speicherabzug geschrieben)


#include <iostream>

int main(int argc, char **argv) {
int* x; *x=2;
return 0;
}

it does compile but says
Speicherzugriffsfehler (Speicherabzug geschrieben)
(Something like segmentation fault in english I think)
Executing in debug mode will say
*** Programm hat Signal SIGSEGV (Segmentation fault) empfangen ***


I am very confused because I have compiled a lot of other programm so far and I did no change anything to my installation...
If anyone as an idea....
I am using ubuntu 12.04

wysota
27th November 2012, 23:27
You have a uninitialized pointer to an int called "x" but there is no object behind it. Dereferencing it tries to overwrite a random address in memory which leads to a segmentation fault.