- #1
Mr Virtual
- 218
- 4
Homework Statement
If I write:
char* Name="Computer";
cout<<Name[0]; //Output: C
cout<<Name[2]; // Output: M
what do the above lines mean? How can a pointer store a string? And why is it acting like an array? Either it is a simple concept that I have forgotten or it is a new concept that I have yet to study.
The Attempt at a Solution
Here, Name is a pointer of char type i.e. it can store the address of a char type variable. We cannot assign a character to a pointer. Then how is it still correct to assign a string to a pointer. What is happening here?
Please Help!
Thanks
Mr V