Pointer to char Array


I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer. Is there anything I am doing wrong here.

#include <iostream>
using namespace std;


int main ()
{
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;

ArraySize = sizeof(ch)/sizeof(char);
cout << endl << endl << " ARRAYSIZE is " << ArraySize << endl;


cout << endl << endl << "Using POINTER ARITHMETIC now " << endl;
for (int i = 0; i < ArraySize; i++, iPtr++){
cout << "The address of index " << i
<< " of the POINTER is "<< iPtr << endl;
cout << "The value at index " << i
<< " of the POINTER is "<< *iPtr << endl;
}
return 0;
}
Change

<< " of the POINTER is "<< iPtr << endl;

to

<< " of the POINTER is "<< static_cast<void *>( iPtr ) << endl;


THank YOu ...Mucho Gracias....Merci....Danke SHoen,,,Arigatoo...Privet Spasivah...
To you abhishekm71 and Vlad......

It is now working using the static_cast
Last edited on
Topic archived. No new replies allowed.