look at the following code
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
class C { public: int a; char b; static int c; };
int C::c = 2;
int main(){
C c;
printf("&C::a = %d, &C::b = %d\n", &C::a, &C::b);
cout << "&C::a = " << &C::a << " &C::b = " << &C::b << endl;
getchar();
return 0;
}
the result i get is
&C::a = 0, &C::b = 4
&C::a = 1 &C::b = 1
So why the result of cout is incorrect?
OK, my illustration of this question is ambigious. i am sorry for that. In fact, I want to ask why &C::a and &C::b will cout 1?
As for the result of printf, %d or %p is no matter. They all get the correct result. The difference between them is just %p will output the result in hex format.
And I also know that it's better to add a (void*) conversion in the cout.
After all, thanks for all of you.