2007/06/26 | 指针的应用及如何来直接操作内存
类别(计算机与编程) | 评论(0) | 阅读(17) | 发表于 14:12

#include <iostream>
#include <string>

using namespace std;

void main()

{
 int a,b;
 int *p1,*p2;
//  void exchanged (int *t1,int *t2);
 
 a=1,b=2;
 p1=&a,p2=&b;

 cout<<"a="<<a<<" , "<<"b="<<b<<" , "<<endl;
 cout<<"a="<<&a<<" , "<<"&b="<<&b<<" , "<<endl<<"\n";

 cout<<"*p1="<<*p1<<" , "<<"*p2="<<*p2<<" , "<<endl; //pointer 's value
 cout<<"p1="<<p1<<" , "<<"p2="<<p2<<" , "<<endl<<"\n"; //pointer 's point the a&b 's add

 int *exchange;
 exchange=p1,p1=p2,p2=exchange;

 cout<<"all things has exchanged by pointer."<<endl<<"\n";

 cout<<"a="<<a<<" , "<<"b="<<b<<" , "<<endl;
 cout<<"a="<<&a<<" , "<<"&b="<<&b<<" , "<<endl<<"\n";

 cout<<"*p1="<<*p1<<" , "<<"*p2="<<*p2<<" , "<<endl; //pointer 's value
 cout<<"p1="<<p1<<" , "<<"p2="<<p2<<" , "<<endl<<"\n"; //pointer 's point the a&b 's add

 p1+=1;
 cout<<"p1="<<p1<<" , "<<"p2="<<p2<<" , "<<endl; //pointer 's point the a&b 's add
  cout<<"p1="<<p1+1<<" , "<<"p2="<<p2<<" , "<<endl; //pointer 's point the a&b 's add
   cout<<"p1="<<p1+2<<" , "<<"p2="<<p2<<" , "<<endl<<"\n"; //pointer 's point the a&b 's add

 cout<<"*p1="<<*p1<<" , "<<"*p2="<<*p2<<" , "<<endl; //pointer 's value
 cout<<"p1="<<p1<<" , "<<"p2="<<p2<<" , "<<endl<<"\n"; //pointer 's point the a&b 's add

 int * pt = (int*)0x0012FF7C; //operation of RAM address
 *pt = 99;
 cout<<"PT = "<<*pt<<endl;
 cout<<"PT = "<<pt<<endl;

/* float * p = (float*)0x0012febc;
 *p = 0.5;  */

 cout<<"*p1="<<*p1<<" , "<<"*p2="<<*p2<<" , "<<endl; //pointer 's value


// return 0;
}

/*void exchanged (int *t1,int *t2)
{
 int *exchange;
 exchange=t1,t1=t2,t2=exchange;
}*/

0

评论Comments

日志分类
首页[666]
计算机与编程[133]
EMU[40]
UFOs[24]
房产[127]
音乐[13]
LOG[0]
经济[120]
影视[3]
物理[7]
数学[8]
社会[105]
职场[9]
生物医学[18]
生活[59]