printf("%d\n", &Foo::c)
: this is undefined behavior, as &Foo::c
is not an integer, but a pointer to member (but, actually, it is usual that the compiler stores pointer to data member as offset, and as 8
is the offset of Foo::c
, 8
is printed).
std::cout << &Foo::c
: this prints the value &Foo::c
. As iostream doesn't have a pointer to member printer, it chooses the closest one: it converts it to bool
, and prints it as integer. As &Foo::c
converted to bool
is true
, 1
is printed.
manpreet
Best Answer
2 years ago
I tried the following code of C++. However, the outputs of
intf">printf
andstd::b.com/tag/cout">cout
are different. Can someone tell me why?