内容纲要
  • %p 输出指针
  • %x 16 进制小写字母
  • %X 16 进制大写字母
  • 0x%I64X 64 位 16 进制
  • std::cout << std::hex << "0x" <<
#include <iostream>
#include <string>
#include <Windows.h>

using namespace std;

int main()
{
    int varInt = 123456;
    string varString = "DefaultString";
    char arrChar[128] = "Long char array right there ->";
    int* ptr2int = &varInt;
    int** ptr2ptr = &ptr2int;
    int*** ptr2ptr2 = &ptr2ptr;

    while (1) {
        cout << "Process ID:\t" << GetCurrentProcessId() << endl;
        cout << "varInt\t\t(" << hex << uppercase << &varInt << ") = " << varInt << endl;
        cout << "varString\t(" << hex << uppercase << &varString << ") = " << varString << endl;
        cout << "arrChar\t\t(" << hex << uppercase << &arrChar << ") = " << arrChar << endl;
        cout << "ptr2int\t\t(" << hex << uppercase << &ptr2int << ") = " << ptr2int << endl;
        cout << "ptr2ptr\t\t(" << hex << uppercase << &ptr2ptr << ") = " << ptr2ptr << endl;
        cout << "ptr2ptr2\t(" << hex << uppercase << &ptr2ptr2 << ") = " << ptr2ptr2 << endl;
        cout << "Press ENTER to print again";
        getchar();
        cout << endl << "------------------------------------" << endl << endl;
    }
}
Process ID:     24336
varInt          (0041F7C4) = 1E240
varString       (0041F7A0) = DefaultString
arrChar         (0041F718) = Long char array right there ->
ptr2int         (0041F70C) = 0041F7C4
ptr2ptr         (0041F700) = 0041F70C
ptr2ptr2        (0041F6F4) = 0041F700
Press ENTER to print again

发表评论

电子邮件地址不会被公开。 必填项已用*标注