+ 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.
7 ответов
+ 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.
+ 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.
+ 1
are you trying to create a variable with the name "*z"?
or are you trying to use the address of the variable z?
+ 1
Create a variable with the address for z.
+ 1
Well, the way you wrote it, you are trying to create an integer variable named "*z"
0
Okay, What would be the proper way then?
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.