Friday 1 July 2016

Confusing C++ Code | C++ Programming Codes

Confusing C++ Code

Description: This is named Confusing because of confusion created by parameters sent by-value and by-reference.


#include <iostream>
using namespace std;

int confuse2(int&a, int&b, int&c){
     a = b + b;
     b = a + c;
     c++;
     return a + c;
}

int confuse(int a, int&b, int&c){
     a = a*b;
     b = b*b;
     c = c*a;
     return confuse2(b, a, a);
}

int main(){

     int a = 5, b = 3, c = 4;
     b = confuse(a, c, b);
     cout << a << endl << b << endl << c << endl;

     return 0;
}


No comments

Post a Comment

Recent Posts