`
Rejoy
  • 浏览: 205246 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

指针问题

阅读更多
1 #include <iostream>
  2 using namespace std;
  3
  4 int main ()
  5 {
  6     char c[5] = "hell";
  7     int i[5] = {1,2,3,4,5};
  8     char a = 'o';
  9
10     char(*p1)[5] = &c;
11     char* p2 = c;
12     int(*p3)[5] = &i;
13     int* p4 =i;
14     char* p5 = &a;
15
16     cout << "p1=" << *p1 << endl;
17     cout << "p2=" << *p2 << endl;
18     cout << "p3=" << *p3 << endl;
19     cout << "p4=" << *p4 << endl;
20     cout << "p5=" << *p5 << endl;
21     return 0;
22 }  
输出结果为:
p1=hell
p2=h
p3=0xbfa401b0
p4=1
p5=o

p1=&c    => *p1就是c
p2=c     => *p2就是c[0]
p3=&i    => *p3就是i
p4=i     => *p4就是i[0]
p5=&a    => *p5就是a
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics