Is impossible without doing things you really shouldn't be doing. For example with strings you might try concatenating them together and splitting it back apart to accomplish a swap, or with integers you might be able to use math to do this. None of these techniques will generalize to an arbitrary data type, however, so my recommendation is:
Just use a third variable and do a standard swap:
Thing first = ...
Thing second = ...
Thing swap = first;
first = second;
second = swap; Is impossible without doing things you really shouldn't be doing. For example with strings you might try concatenating them together and splitting it back apart to accomplish a swap, or with integers you might be able to use math to do this. None of these techniques will generalize to an arbitrary data type, however, so my recommendation is:
Just use a third variable and do a standard swap:
Thing first = ...
Thing second = ...
Thing swap = first;
first = second;
second = swap;
example: x = x-y; y = y-x; x = y-x; <><><> It is not possible to swap two variables without using a temp variable. The code in the answer above, while clever, does not swap the variables. It will exchange the variable values for certain values of x and y, e.g. when x and y are small integers. If x and y are other values, such as strings, pointers, Infinity, NaN (not a number), floating point, or near the limits of the representation (causing over/underflow) then the code will not "swap" the values. <---> Note: there is absolutely no point in swapping two variables without using temopral variable, it's just a typical homework question, already asked here countless times. Another variation: a ^= b; b ^= a; a ^= b;
Just one value can be changed.
Variables allow one to summarise a lot of information using just a variable and a related function.
That is not possible by using just those three ingredients
If you're performing an experiment in which your result depends on multiple variables, but you're just interested in how one of those variables effects the result, you would generally keep all of the other variables constant in order to negate their effects. Those variables that you're keeping constant are called control variables, and you would choose them based on the experiment. For example, say you wanted to determine how changes in resistance effect a circuit's current. Well, current is dependent on not only resistance, but voltage as well, and since you're only interested in the effects of resistance, you would make voltage the control variable, keeping it constant.
O(n*2) for n characters. It is more efficient to simply walk from both ends of the string, swapping characters as you go, reducing the complexity to just O(n/2).
-317
q only if p. The converse of a statement is just swapping the places of the two terms.
Explanatory and Response variables are just fancy words for independent and dependent variables. Explanatory is the independent variable and response is the dependent variable.
Non-using of temporal variable. It is possible, but has no use in real programming. Eg. a := a XOR b b := a XOR b a := a XOR b I warn you again: this is just a curiosity, not something you really use.
Yes. Using an array when multiple elements need to be created at a time is always a better idea than declaring multiple variables. For ex: Int i, j, k; Int[] arr; I have declared 3 int variables and another array just below it. Here since we are using only 3 variables, we can manage to use them without issues but if the number crosses 5 or even more then definitely using an array is always the best option.
As my math teacher would say, the Math gods just picked those random variables to represent these things. There is no specific reason to my knowledge.