本文共 733 字,大约阅读时间需要 2 分钟。
通过这个例子边可以看出区别,而且注意一定要用标准C++的样式
打好基础
#include
#includeusing namespace std;
int add1CallByValue(int t); //define function
void add1ByPointer(int* t);
void add1ByReferrence(int& t);
int main(void)
{ int count=12; std::cout< add1CallByValue(count); //call by value std::cout< std::cout< add1ByPointer(&count); //call by pointer std::cout< std::cout< add1ByReferrence(count); //call by referrence std::cout< system("pause"); return(0);}int add1CallByValue(int t)
{ return(t+1);}void add1ByPointer(int* p)
{ *p+=1;}void add1ByReferrence(int& t)
{ t+=1;}来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-963354/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10748419/viewspace-963354/