void swap(int a,int b)
{
a=a+b;
b=a-b;
a=a-b;
}
in this code always gives the same result for all case
Answers were Sorted based on User's Feedback
Answer / k.kavitha
NO,if the values of a&b are 10,20 respectively., Then
a=a+b becomes "a=30"
b=a-b becomes b=30-20 i.e., "b=10"
a=a-b gives a=30-10 i.e., "a=20"
| Is This Answer Correct ? | 20 Yes | 6 No |
Answer / moorthy
here a and b are local variable in function swap() where a
and b are swapped inside swap().so that swaping does not
affect variable in main().
| Is This Answer Correct ? | 12 Yes | 1 No |
Answer / prateek
Actually this code is for interchanging values of two
variables without using third variable
| Is This Answer Correct ? | 9 Yes | 1 No |
Answer / mangala pandi p
provided a+b is between the int minimum and int maximum
so the answer is no.
| Is This Answer Correct ? | 6 Yes | 5 No |
Answer / shouvik mitra
This code gives the interchange values of the two variables.But this code can also give the same result for the two variables when same numbers are inputted in both the variables, i.e. say a=5,b=5.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sayantan ghosh
This will never give a result as its call by value and even the values arnt printed in the function so the values in main will only be present
| Is This Answer Correct ? | 0 Yes | 0 No |
What is difference between stdio h and conio h?
What are the three constants used in c?
a simple c program using 'for' loop to display the output 5 4 3 2 1
What is calloc malloc realloc in c?
What is meant by operator precedence?
What is the purpose of type declarations?
List some of the static data structures in C?
regarding the scope of the varibles;identify the incorrect statement: a.automatic variables are automatically initialised to 0 b.static variables are are automatically initialised to 0 c.the address of a register variable is not accessiable d.static variables cannot be initialised with any expression
What are examples of structures?
write a program that will read the temperature in Celsius and convert that into Fahrenheit.
What is the difference b/w main() in C language and main() in C++.
how to generate the length of a string without using len funtion?