int n = 10;
int* p = &n;
printf("%p\n", &n)
cout
, you must convert the "pointer to char" to other
type of pointer, otherwise when cout
gets a pointer to
char, it will try to output a sequence of characters, starting from the
address pointed by that pointer, until it encounters '\0'.
reverse()
.
#include <iostream>
using std::cout;
using std::endl;
void reverse(const char* s) {
if (*s == '\0')
return;
reverse(s+1);
cout << *s;
}
int main()
{
reverse("ALICE"); cout << endl;
return 0;
}
E - 0x7ffc20c0bcf8
C - 0x7ffc20c0bd18
I - 0x7ffc20c0bd38
L - 0x7ffc20c0bd58
A - 0x7ffc20c0bd78