ITPub博客

首页 > 应用开发 > IT综合 > Learn c++ step by step (转)

Learn c++ step by step (转)

原创 IT综合 作者:gugu99 时间:2007-08-17 09:59:29 0 删除 编辑
Learn c++ step by step (转)[@more@]

通过这个例子边可以看出区别,而且注意一定要用标准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<  system("pause");
  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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3121
  • 访问量
    2644420