Sep 3, 2012 at 5:01pm UTC
char chArray[] = "0123456789";
char* ptr = chArray;
char* ptr1 = "chArray";
using namespace std;
int main()
{
cout << ptr1<< endl;
return 0;
}
When I run the above code it will print 'chArray'. But I want to print '0123456789' using ptr1 or the content of ptr1 (ie., chArray).
How can I do this?
Please help... It's kind of urgent!
Sep 3, 2012 at 5:04pm UTC
ptr1 is pointing to a string, and not chArray ; "chArray" and chArray are two completely different things.
Wazzak
Sep 3, 2012 at 5:16pm UTC
You could substitute ptr1 for ptr in the statement
cout << ptr1<< endl;
that is you could write
cout << ptr << endl;
and you would get the contents of the array.
ptr points the first element of array chArray after its initialization in the statement
char* ptr = chArray;
while ptr1 points to the first element of the string literal "chArray"