Created
September 22, 2013 19:59
-
-
Save wszdwp/6663231 to your computer and use it in GitHub Desktop.
Cracking the interivew 19.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Java is not working ??? pass by value?? | |
public class Question191 | |
{ | |
public static void swap(int a, int b) { | |
a = a ^ b; | |
b = a ^ b; | |
a = a ^ b; | |
} | |
public static void main(String[] args) { | |
int a = 2; | |
int b = 3; | |
//Question191 test1 = new Question191(); | |
System.out.println("a, b = " + a +", " + b); | |
swap(a, b); | |
System.out.println("After swap, a, b = " + a +", " + b); | |
} | |
} | |
//C++ code is working | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
int a = 2; | |
int b = 3; | |
a = a - b; | |
b = b + a; | |
a = b - a; | |
cout << "a = " << a << endl; | |
cout << "b = " << b << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment