Created
October 15, 2013 04:59
-
-
Save boycgit/6986722 to your computer and use it in GitHub Desktop.
使用引用、指针操作变量(C++)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int a = 20; //声明一个int变量 | |
| int &b = a; //声明一个int引用 | |
| int *p = &a;//声明一个int指针 | |
| cout<<"start,a="<<a<<endl; | |
| b = b+1; | |
| cout<<"then,b+1 = "<<b<<endl; | |
| *p=*p+1; | |
| cout<<"then,*p+1 = "<<*p<<endl; | |
| cout<<"final,a="<<a<<endl; | |
| return 0; | |
| }; | |
| /*====result==== | |
| start,a=20 | |
| then,b+1 = 21 | |
| then,*p+1 = 22 | |
| final,a=22 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment