19 votes 19 votes What does the following code do? var a, b: integer; begin a:=a+b; b:=a-b; a:a-b; end; exchanges $a$ and $b$ doubles $a$ and stores in $b$ doubles $b$ and stores in $a$ leaves $a$ and $b$ unchanged none of the above Algorithms gate1993 algorithms identify-function easy + – Kathleen asked Sep 29, 2014 recategorized Apr 22, 2021 by Lakshman Bhaiya Kathleen 4.2k views answer comment Share Follow See 1 comment See all 1 1 comment reply Raghav Chandra commented Mar 24, 2018 reply Follow Share typo mistake in a:a-b; it should be a:=a-b; 0 votes 0 votes Please log in or register to add a comment.
Best answer 27 votes 27 votes Answer is simply $A$ i.e. it swaps the values of the two.. Take any two values for $A$ and $B$. and perform the given operations over them. Gate Keeda answered Oct 1, 2014 edited Jun 12, 2018 by Milicevic3306 Gate Keeda comment Share Follow See all 3 Comments See all 3 3 Comments reply neel19 commented Feb 2, 2021 reply Follow Share If a and b are the same, can we say that values have been changed? 0 votes 0 votes Pavankumar07 commented Aug 4, 2021 reply Follow Share if we consider all cases then option E is correct. 0 votes 0 votes Kiyoshi commented Nov 5, 2021 reply Follow Share You can consider any case answer will be option A. 0 votes 0 votes Please log in or register to add a comment.
6 votes 6 votes (a) initially a = 10 b = 5 a = 15 b = 10 a = 5 Manu Thakur answered Oct 9, 2014 Manu Thakur comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes 1. a= a+b 2. b= a-b= (a+b)-b= a (from 1) 3. a= a-b= (a+b) - (a) = b (from 1 and 2) Hence the values are getting exchanged Answer(A). Prateek K answered Apr 11, 2018 Prateek K comment Share Follow See all 0 reply Please log in or register to add a comment.