+ 1

Program has triggered a break point.

While debugging my program, the debugger I use throws any exemption of: Invalid address specified to RtlValidateHeap( 0000027284900000, 0000027284905018 ). Here is the code: int *z = new int; do { *z++ } while(*z < 5); delete z; I am not sure what I am doing wrong.

7th Aug 2018, 1:04 AM
Jordan
Jordan  - avatar
7 odpowiedzi
+ 4
int z = 5; //example z declaration int *p = &z; //create pointer p with address of z do{ *p++; //increment the variable that z points to } while(*p < 5); This should work. there are other ways you can do it, also. You can use z instead of *p. Really, there is no reason to use *p here.
10th Aug 2018, 12:21 PM
J.G.
J.G. - avatar
+ 2
Oh, I think I finally get what you were trying to do. #include <iostream> using namespace std; int main() { int *p = new int; // request memory *p = 5; // store value cout << *p << endl; // use value delete p; // free up the memory return 0; } This is taken directly from the tutorial.
11th Aug 2018, 2:10 AM
J.G.
J.G. - avatar
+ 1
are you trying to create a variable with the name "*z"? or are you trying to use the address of the variable z?
7th Aug 2018, 1:43 AM
J.G.
J.G. - avatar
+ 1
Create a variable with the address for z.
7th Aug 2018, 2:08 AM
Jordan
Jordan  - avatar
+ 1
Well, the way you wrote it, you are trying to create an integer variable named "*z"
9th Aug 2018, 11:33 PM
J.G.
J.G. - avatar
0
Okay, What would be the proper way then?
10th Aug 2018, 12:58 AM
Jordan
Jordan  - avatar
0
So I am new to C++ and was trying to use dynamic memory simply to test my knowledge. How do I create a new variable for dynamic memory.
10th Aug 2018, 12:35 PM
Jordan
Jordan  - avatar