Full disclosure: This is homework. I'm just really confused about one part. I have this code in a c++ program:
char * charArray = new char[100];
//fill charArray
char c = '.';
for(int i=0; i<100; i++)
{
charArray[i] = c;
c = c + 1;
}
cout <<"Char Array: " << endl;
for(int i=0; i<100; i++)
{
cout << "Type: Char @ " << &charArray[i] << " = " << charArray[i] <<endl;
}
At a different point in my program I have pretty much the exact same code but instead of a char array it is a float array. When I print out the float array I get Type: Float @ whatAppearsToBeAProperMemoryAddress = correctFloat#.
However although the chars are correct the address don't appear to be. The address for the char array go like this:
./0123456789<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~??????????????????
/0123456789<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
abcdefghijklmnopqrstuvwxyz{|}~??????????????????
.... all the way to ?? ?
So obviously instead of getting the address I am getting varying degrees of what should be the contents of the array. I am very confused and any pointers would be appreciated. This is my first crack at c++.