欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
Learn c++ step by step
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 

通过这个例子边可以看出区别,而且注意一定要用标准C++的样式

打好基础

#include <iostream>
#include <cstdlib>

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<<count<<endl;
   
    std::cout<<"add1CallByPointer";
    add1ByPointer(&count); //call by pointer
    std::cout<<count<<endl;
   
    std::cout<<"add1ByReferrence";
    add1ByReferrence(count); //call by referrence
    std::cout<<count<<endl;
    system("pause");
    return(0);
}

int add1CallByValue(int t)
{
    return(t+1);
}

void add1ByPointer(int* p)
{
    *p+=1;
}

void add1ByReferrence(int& t)
{
    t+=1;
}


附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步