+ 1
Why do we need to declare pointer dataype with string while it has a hexadecimal integer??
Say, string x="asdg"; int *p=&x; //It shows an error why???we store hexadecimals in it.
1 Antwort
+ 5
This is actually quite straightforward.
You are literally asking this:
https://stackoverflow.com/questions/19292224/why-do-we-need-different-datatype-for-pointer
When you do &x, the address pointing to the first character in the string is returned, but not for the rest of the characters. E.g.
0x7ff950 <- &x will only return this address
0x7ff954
0x7ff958
0x7ff95c
This shows one of the possible differences between int* and std::string*.