Chinaunix首页 | 论坛 | 博客
  • 博客访问: 136159
  • 博文数量: 38
  • 博客积分: 306
  • 博客等级: 二等列兵
  • 技术积分: 335
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-29 15:19
文章分类

全部博文(38)

文章存档

2013年(23)

2012年(15)

我的朋友

分类: C/C++

2013-08-05 18:12:55


点击(此处)折叠或打开

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;

  4. int main()
  5. {
  6. int a=10;
  7. int *pt=&a;
  8. printf("%d:\n",pt);//十进制的数值 pt=&a;
  9. printf("%p:\n",pt);//十六进制的数值
  10. printf("%d:\n",&a);
  11. cout<<pt<<endl;///等价于 printf("%p:\n",pt); 输出的是pt指针变量存储的内容。

  12. string str="abv";
  13. cout<<str<<endl;
  14.  char *p="abc";
  15.  cout<<"p:"<<p<<endl;////输出p所指向的内存值打印出来。
  16.  printf("%d:\n",p);
  17.   printf("%p:\n",p);
  18.  cout<<"*p:"<<*p<<endl;
  19.  cout<<"&p:"<<&p<<endl;
  20.  int i=(int)"abc";
  21.  int i2=(int)p;
  22. // int i3=static_cast<int>(&p); //// 错误,不能从char **int 转换。
  23. int i5=reinterpret_cast<int>(&p); //// 底层bit复制,所以是可以的。
  24. cout<<i<<endl;
  25. cout<<i2<<endl;
  26. cout<<i5<<endl;
  27. return 0;
  28. }

结果:
阅读(2401) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~