In C++ could someone clarify
1- In he following code, printing char*
is displayed as bunch of random characters, but printing string*
is just an integer address? Why so?
int * intptr;
char * charptr;
std::string * stringptr;
float * floatptr;
//printing
std::cout << intptr << " , " << charptr << " , " << stringptr << " , " << floatptr << "\n";
output:
0x7ffeea2f1a60 , ���� , 0x7ffeea2f1a48 , 0x1092d13d4
2- charptr
is a pointer variable painting to part of memory that contains a character. Just for curiosity, how do you print the address of charptr
?
3- While reading different sources, I came across to this: "The different printing is because of the functions (i.e. a const char *)
that treat that memory as a sequence of characters". Could someone expand this answer w.r.t the above code?