exercises 2.34

 1 #include <iostream>
 2 using namespace std;
 3 
 4     
 5 int main()
 6 {
 7         int i=0,&r=i;
 8         auto a=r;
 9         
10         const int ci=i,&cr=ci;
11         auto b=ci;
12         auto c=cr;
13         auto d=&i;
14         auto e=&ci;
15         
16         const auto f=ci;
17         
18         auto &g=ci;
19     //    auto &h=42; 非常量引用不能绑定字面值 
20         const auto &j=42;
21         auto k=ci,&l=i;
22         auto &m=ci,*p=&ci;
23         
24         a=42;b=42;c=42;
25         cout<<*d<<endl;
26         cout<<*e<<endl;
27         cout<<g<<endl;
28     //    d=42; 出错,是指针 
29     //    e=42; 出错,是指向常量的指针 
30     //    g=42; 出错,是常量的引用 
31     
32     
33     return 0;    
34 }

 

posted @ 2015-04-13 19:09  无敌烤皮蛋  阅读(96)  评论(0)    收藏  举报