c++ - confusion of char* str="ab", str and &str -
i learning pointer , code. defined pointer char (string actually) *str , pointer int *a, defined in same way. thought both str , a should address, when tried output str , &str, a , &a, found str not address, string. difference between char *str , int *a in terms of type of str , a? thank you.
#include<iostream> #include<string> using namespace std; int main() { char *str = "fa"; cout << "str: " << str << endl; cout << "&str: " << &str << endl; int b = 5; int *a = &b; cout << "a: " << << endl; cout << "&a: " << &a << endl; } this output:
str: fa &str: 0x7fff5a627280 a: 0x7fff5a62727c &a: 0x7fff5a627288
the << operator streams has overload char * outputs c-style string. want, if it's not want, can use reinterpret_cast<void*> or addressof.
Comments
Post a Comment