how to swap to variables without using thrid variable in java?
Answers were Sorted based on User's Feedback
Answer / igor polivanyi
It’s pretty simple:
int a = 12;
int b = 34;
a = a + b;
b = a - b;
a = a - b;
And for real cowboys, it could be simplified further:
a -= (b = (a += b) - b);
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / hemant verma
a=a^b^(b=a);
Hemant Verma
FameofLight@gmail.com
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / mani
int x = 15;
int y = 20;
System.out.println(x+" "+y);
x ^= y;
y ^= x;
x ^= y;
System.out.println(x+" "+y);
Is This Answer Correct ? | 2 Yes | 1 No |
Which keyword is written to use a variable declared in one class in the other class?
In multiple inheritance , to create sub class object , is there need to create objects for its superclasses??? in java and c++ both. Actually i have some information that is , all available members from its superclasses , memory created in subclass obj , so no need to create object for its superclasses...??? Thanks in Advance
what is different between oops and c++
What are the advantages of polymorphism?
Why and when is a virtual destructor needed?
what is abstract class ? when is used in real time ? give a exp
What language is oop?
how many types of notations are in java
1 Answers National University of Modern Languages (NUML),
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
You have one base class virtual function how will call that function from derived class?
What are the different forms of polymorphism??
Which is the only operator in C++ which can be overloaded but NOT inherited?