Skip to content

Instantly share code, notes, and snippets.

@boycgit
Created October 15, 2013 04:59
Show Gist options
  • Save boycgit/6986722 to your computer and use it in GitHub Desktop.
Save boycgit/6986722 to your computer and use it in GitHub Desktop.
使用引用、指针操作变量(C++)
#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