2

だから私の疑問は、私は値による呼び出しを試みていたということです.与えられたコードを実行している間、int main()の後に関数定義を書くとスワッピングが起こりますしかし、int main()の上に関数定義をカットアンドペーストすると、スワップは起こります起こらない。何故ですか?


#include<iostream>
#include<string>
#include<vector>
#include<bitset>
#include<fstream>
using namespace std;
#define ADDU 1
#define SUBU 3
#define AND 4
#define OR  5
#define NOR 7
#define MemSize 65536
void swap(int a, int b)
{
    int temp = a;
    a = b;
    b = temp;
}

int main(){
    // int a = 20;
    // int *p = &a;
    // cout<<"P: "<<p<<endl<<"*P gives: "<<*p<<endl<<"&p gives: "<<&p<<endl<<"&a : "<<&a;;

    int x,y;
    x = 10;
    y = 20;
    cout<<"Before Swapping: "<<"x: "<<x<<endl<<"y: "<<y<<endl;
    swap(x,y);
    cout<<"After Swapping: "<<"x: "<<x<<endl<<"y: "<<y<<endl;
}
4

1 に答える 1