zoukankan      html  css  js  c++  java
  • 20180318 代码错题(2)

    程序段的执行结果是()
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    #include <iostream>
    using namespace std;
     
    void fun1(int &x) {
        x++;
    }
     
    void fun2(int x) {
        x++;
    }
     
    int main() {
        int abc = 100, xyz = 13;
        fun1(xyz);
        abc = xyz;
        fun2(abc);
        printf("%d ", abc);
    }
    100
    13
    12
    14

    答案 D  错选 B
    fun1(xyz) 传引用,值本身被改变。
    fun2(abc)值传递,改变的是形参,实参没有影响。
    abc被xyz赋值,所以值为14


  • 相关阅读:
    简化单例模式
    static
    单例模式之懒汉模式
    Car race game
    poj-2403
    poj-2612
    poj-1833
    poj--2782
    poj--2608
    poj--3086
  • 原文地址:https://www.cnblogs.com/kxzh/p/8597950.html
Copyright © 2011-2022 走看看