So my doubt is, I was trying out call by value, While running the given code, Swapping happens when I write the function definition after int main() But if I cut and paste the function definition above int main(), the swap does not take place. Why is that?
#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;
}