首页 > 应用开发 > IT综合 > Learn c++ step by step (转)
通过这个例子边可以看出区别,而且注意一定要用标准C++的样式
打好基础
#include
#include
using namespace std;
int add1CallByValue(int t); //define function prototype
void add1ByPointer(int* t);
void add1ByReferrence(int& t);
int main(void)
{
int count=12;
std::cout<<"add1CallByValue";
add1CallByValue(count); //call by value
std::cout<
std::cout<<"add1CallByPointer";
add1ByPointer(&count); //call by pointer
std::cout<
std::cout<<"add1ByReferrence";
add1ByReferrence(count); //call by referrence
std::cout<
return(0);
}
int add1CallByValue(int t)
{
return(t+1);
}
void add1ByPointer(int* p)
{
*p+=1;
}
void add1ByReferrence(int& t)
{
t+=1;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10748419/viewspace-963354/ ,如需转载,请注明出处,否则将追究法律责任。