Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

To find whether a number is even or odd without using any conditional operator??

12 Answers   College School Exams Tests, IBM,


Write a program in c to input a 5 digit number and print it in words.

11 Answers  


Why static variable is used in c?

0 Answers  


Is int a keyword in c?

0 Answers  


Is main is user defined function?

0 Answers  


What are the main characteristics of c language describe the structure of ac program?

0 Answers  


How we can write a value to an address using macro..?

0 Answers   Tata Elxsi,


What is the use of pragma in embedded c?

0 Answers  


main() {int a=200*200/100; printf("%d",a); }

14 Answers   TCS,


What are the different pointer models in c?

4 Answers  


write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?

0 Answers  


Reverse the part of the number which is present from position i to j. Print the new number. eg: num=789876 i=2 j=5 778986

1 Answers  


Categories