Ask Question
5 June, 23:58

Given two int variables, i and j, which have been declared and initialized, and two other int variables, itemp and jtemp, which have been declared, write some code that swaps the values in i and j by copying their values to itemp and jtemp respectively, and then copying itemp and jtemp to j and i respectively.

+3
Answers (1)
  1. 6 June, 00:33
    0
    itemp = i; jtemp = j; i = jtemp; j = itemp; The above code example assumes that you're writing in C, C++, java, or some other language with similar syntax. Since all the variables i, j, itemp, and jtemp have the same type, you can simply assign one to another without having to worry about type compatability or conversions. When the 4 assignment statements have executed, i will have the original value of j, and j will have the original value of i, effectively swapping the two values between the two variables.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Given two int variables, i and j, which have been declared and initialized, and two other int variables, itemp and jtemp, which have been ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers