Upon running this program (which is trying to print the addresses of various dynamically allocated variables and arrays), all of the addresses are provided save those belonging to the char array's elements.Code:#include <iostream> using namespace std; int main() { int * myInt = new int; long *myLong = new long; char* myChar = new char[100]; float* myFloat = new float[100]; cout << "&myInt's new = " << myInt << ".\n"; cout << "&myLong's new = " << myLong << ".\n"; for(int i = 0; i < 100; i++) { cout << "&myChar's new element [" << i << "] = " << &(myChar[i]) << ".\n"; } [B] for(int i = 0; i < 100; i++) { cout << "&myFloat's new element [" << i << "] = " << myFloat << ".\n"; myFloat++; } delete myInt; delete myLong; delete []myChar; delete []myFloat; return 0; }
Instead of their arrays, lines such as
FP_NO_HOST_CHECK=NO and
ComSpec=C:\WINDOWS\system32\cmd.exe are printed in various degrees of truncation. Do these have anything to do with previous contents of the heap?
More importantly, how can I get the source code to print out the addresses properly?