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



void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

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

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

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

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

Answer / prateek

Actually this code is for interchanging values of two
variables without using third variable

Is This Answer Correct ?    9 Yes 1 No

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

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

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

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

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

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

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

Answer / sourabh

no,result will depend on the values of a nd b

Is This Answer Correct ?    0 Yes 2 No

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

Answer / shruti

Sorry, it does nott.. :-)
it works proper..

Is This Answer Correct ?    1 Yes 4 No

void swap(int a,int b) { a=a+b; b=a-b; a=a-b; } in this code always gives the same result fo..

Answer / sunny

NO
Means we can give diff values give different answer.
like
we can give a=80,b=100
a=180,b=20,a=20

Is This Answer Correct ?    3 Yes 9 No

Post New Answer

More C Interview Questions

Explain what are multibyte characters?

0 Answers  


what is the basis for selection of arrays or pointers as data structure in a program

0 Answers   TCS,


Explain how can I avoid the abort, retry, fail messages?

0 Answers  


we have a 3litres jug and a 5 litres jug and no measures on them. using these two jugs how can we measure 4 litres of water?

2 Answers   Convergys,


what is a constant pointer in C

0 Answers  






what are brk, sbrk?

1 Answers   Oracle,


what is out put of the following code? #include class Base { Base() { cout<<"constructor base"; } ~Base() { cout<<"destructor base"; } } class Derived:public Base { Derived() { cout<<"constructor derived"; } ~Derived() { cout<<"destructor derived"; } } void main() { Base *var=new Derived(); delete var; }

3 Answers   Honeywell,


How to write in a function declaration and in function call in which the function has 'n' number of varible or arguments?

2 Answers  


What is the general form of a C program?

0 Answers  


Is the following code legal? struct a { int x; struct a b; }

4 Answers  


Why cd or dvd are round why not square.

1 Answers  


int main(){ float f=8.0; if(f==8.0) printf("good"); else printf("bad"); } what is the answere and explain it?

3 Answers  


Categories