我写了一个像这样的c ++代码:
#include <iostream>
using namespace std;
int main() {
int i = 2;
int i2 = 0;
void *pi = &i - 1;
cout << "by cout - the value of *pi is: " << *(int*)pi << endl;
printf("by printf - the value of *pi is: %d\n", *(int*)pi);
printf("the address of pi is: %p\n", pi);
printf("the address of i2 is: %p\n", (void*)&i2);
printf("the value of i2 is: %d\n", i2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
by cout - the value of …Run Code Online (Sandbox Code Playgroud)