1>
#include<iostre am>
using namespace std;
2>
i have written this two simple program. but the problem is that in the first case both the cout is being printed but is the second case the cout inside the defination of the swap function is not printer. can any one please let me understand why? pzzzzzzzzzzzz
#include<iostre am>
using namespace std;
Code:
void swap(int& i, int& j) { int tmp = i; i = j; j = tmp; cout<<"The value after swap of x and y is"<<i<<" "<<j<<endl; } int main() { int x, y; cout<<"enter the value of x and y"<<endl; cin>>x>>y; swap(x,y); cout<<"The value after swap of x and y is"<<x<<" "<<y<<endl; }
Code:
#include <iostream> using namespace std; main() { int a,b; //void swap(int a,int b); cout<<"enter the value of a and b"<<endl; cin>> a>>b; swap (a,b); cout<<"The value after swap is"<<a<<":"<<b<<endl; } void swap(int& x, int& y) { x=x+y; y=x-y; x=x-y; cout<<"The value after swap is"<<x<<"\t"<<y<<endl; }
Comment