Reputation: 9841
I am trying to access uninitialized memory,
int *ptr;
// to this and that
*ptr = 8;
return 0;
I get following exception,
Unhandled exception at 0x0041145e in sam2.exe: 0xC0000005: Access violation writing location 0xcccccccc.
Now I know 0xcccccccc
is value used for uninitialized pointers in Visual C++. But I do not understand meaning of 0x0041145e
and 0xC0000005
.
Just to clarify, I am asking this question because I am trying to make video tutorial on YouTube regarding Magic Numbers.
I appreciate your help.
Upvotes: 0
Views: 206
Reputation: 61
This is a wrong way of using pointer. int *ptr; The above line is telling you that ptr hold a address to a pointer. By default the address stored is some garbage depending on the compiler, by the error you are getting it is safe to assume that the address is 0xcccccccc
0x0041145e, is the the address of the instruction, which is being executed, or this is the instruction on top of the stack.
so your code has not executed. Kindly Modify the code like this.
int *ptr = (int *)malloc(sizeof(int));
*ptr = 8;
return 0;
Upvotes: 0
Reputation: 2590
0xC0000005
is the access violation error code. Such illegal operations with pointers result in an access violation so this code will be seen. On the other hand 0x0041145e
isn't a magic number, it's the location of the offending instruction in the executable, and will be different for other programs doing the same thing.
Upvotes: 3