间接修改指针的地址
代码:
// test for a pointer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef struct
{
int *p;
}Test;
int main( )
{
int *p;
// p[0] = 4;
// p[1] = 3;
Test test;
p = (int *)&test;
p[0] = 1;
cout << "p[0] = " << p[0] << endl;
cout << "test.i = " << test.p << endl;
return 0;
}
C++如何修改指针的地址
发布于: 2011-12-13 | 分类: C++
热门分类
推荐阅读
- g++链接报undefined reference to的排查方法(静态库顺序、--start-group与nm -C、c++filt定位符号)
- C++程序报double free or corruption与free(): invalid pointer的排查方法(glibc堆破坏、MALLOC_CHECK_与valgrind定位)
- C++编译报错C1083无法打开包括文件与LNK1104无法打开文件的排查方法(附加包含目录、平台工具集与Windows SDK版本定位)
- C++程序崩溃报0xC0000005访问冲突的定位方法(dump文件抓取、Windbg与AddressSanitizer排查内存越界)
- 报错丢失MSVCP140.dll、VCRUNTIME140.dll与应用程序无法正常启动0xc000007b的解决方法(VC++运行库版本对应、32位与64位混用排查、/MT与/MD)