| yamen ajjour (6) | |||
|
i have a question that confusing me alot we know in c++ to declare an pointer-based string we use the code
but my question is that we know if i write cout<<ptr;this must output the location that ptr pointed to but here the confusing is this code will output the string that pointer hold why ?? | |||
|
|
|||
| helios (10126) | |
|
I do hope you made that pointer point to something before you wrote to the location it points to. std::cout interprets passing pointers to char, and only pointers to chars, as the intention to print the C string they point to. If you need to print the actual address, cast the pointer to anything. void *, for instance. | |
|
|
|
| yamen ajjour (6) | |||
i wrote this program to reverse a string and as you see i used pointers here , but the program still doesn't work ?? can you help me i have seen that pointer str didn't point to the first char but it points to all the string while swap points to the last character int the string and when compiler reach to this line *(swap-i)=*(str+i);the program return a run time error | |||
|
Last edited on
|
|||
| jsmith (5804) | |
|
Line 8 is wrong... you need to make a char array instead. | |
|
|
|
| yamen ajjour (6) | ||
thank you but can you tell me why the code above is incorrect ? ididn'tt get the idea here | ||
|
|
||