c++ 参数传递

// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>

void max(int a, int b)
{
    a = 1;
    b = 2;
}

void fn(int& a, int& b)
{
    a = 1;
    b = 2;
}

void test(int* a, int* b)
{
    *a = 8;
    *b = 9;
}
int main()
{
    int num1 = 100;
    int num2 = 200;
    //赋值,不可修改变量
    max(num1, num2);
    std::cout << num1 <<","<<num2<< std::endl;
    //引用,可修改变量
    fn(num1,num2);
    std::cout << num1 << "," << num2 << std::endl;
    //指针,可修改变量
    test(&num1, &num2);
    std::cout << num1 << "," << num2 << std::endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_24127015/article/details/86599430
今日推荐