+ 1

What is the function of variable temp

22nd Jun 2017, 2:38 PM
Muskan Agrawal
5 Respostas
+ 2
hi, temp car used to store the value of var temporarily. but this temp will consume some resources and u can avoid to use this temp. with using temp var to swap two numbers ******************************************** swap=changing the value of two variables. temp=a; a=b; b=temp; here value of a and b is 5 and 10 then after executing the above code the value of a and b is 10 and 5 respectively. without using temp variable ***************************** a=a+b; b=a-b; a=a-b; by executing the above code will also swap the variables
22nd Jun 2017, 5:42 PM
Nanda Balakrishnan
+ 2
interchanging like i have done put the value of b in a and vice versa
22nd Jun 2017, 2:45 PM
Palak Bajla
Palak Bajla - avatar
+ 2
swapping means interchanging the values of 2 variable eg: int a=1,b=2,temp; a=temp; b=a; a=temp; The above code will swap the values in a and b then the value a will be 2 and b will be 1
22nd Jun 2017, 2:59 PM
MAK 786
MAK 786 - avatar
+ 1
it is generally used when we need temporary variables like for swapping two numbers. temp=a; a=b; b=temp;
22nd Jun 2017, 2:44 PM
Palak Bajla
Palak Bajla - avatar
0
swapping means
22nd Jun 2017, 2:45 PM
Muskan Agrawal