That is correct, once again I have a question, lol. In the following code, I was practicing how to use New and Delete with Pointers. In my little while loop, LocalVariable++ does exactly what I thought it would do, increments by 1. However, the next line *pHeap +=1, I had originally put in *pHeap++ thinking it would do the exact same, increment by 1....however, that did not happen. Instead I got all kinds of weird values for *pHeap and a Debug Assertion Failed error. Now my understanding is that using the * in front of the variable gives me the value at pHeap, correct? Why then would a simple ++ not work?
Thanks,
Shawn
*Edit* What is a debug assertion fail error anyhow? lol, i guess i can google that, evidentally it is something bad, ;).
//Using New and Delete and Pointers#include <iostream>int main(){ using namespace std; unsigned short LocalVariable = 0; //creates a local variable in main unsigned short *pLocalVariable = &LocalVariable; //creates a pointer to LocalVariables address unsigned short *pHeap = new unsigned short; //creates a pointer on the heap(free store) *pHeap = 1; //assigns the value 1 to the heap variable pHeap while (LocalVariable<10) { cout<<"LocalVariable = "<<LocalVariable<<endl; cout<<"*pLocalVariable = "<< *pLocalVariable<<endl; cout<<"*pHeap = "<< *pHeap<<endl; LocalVariable++; *pHeap += 1; } delete pHeap; return 0;}
[Edited by - shawnre on June 3, 2007 11:27:17 AM]