一、查看变量内存和内存中的值
命令语法:x /选项 内存地址
调试代码示例:
#include <iostream> #include <cstring> using namespace std; struct test_struct { char name[12]; char gender; int age; };
int test_memory() { const char* test_str="this is a test"; int itest = 0x12345678; struct test_struct test; memset(&test,0,sizeof(test)); test.age = 25; strcpy(test.name,"SimpleSoft"); test.gender = 'm'; cout << test_str << " " << itest << endl; return 0; } int main(int argc,char** argv) { test_memory(); return 0; }
查看整型变量内存地址中的值:
查看字符串变量的内存地址(字符串本身就是一个指针):
查看结构体变量的内存地址:
二、修改变量内存中的值