23 23 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$ unchangednone of the above Algorithms gate1993 algorithms identify-function easy + – Kathleen 7.4k views answer comment Share Follow Print See all 3 Comments 3 3 Comments reply Raghav Chandra commented Mar 24, 2018 reply Follow flag typo mistake in a:a-b; it should be a:=a-b; 1 1 replyShare Shaik Masthan commented May 15, 2024 reply Follow flag @Raghav ChandraCorrected 👍 0 0 replyShare Kshitij Sharma commented Jan 14, 2025 reply Follow flag Level : easy : 3 3 replyShare Please log in or register to add a comment.
Best answer 34 34 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 6 Comments 6 6 Comments reply Show 3 previous comments halfcodeblood commented May 15, 2024 reply Follow flag @Kiyoshi for a=2 b=3? 0 0 replyShare Shaik Masthan commented May 15, 2024 reply Follow flag @halfcodebloodwhat's the problem with that case ? 0 0 replyShare halfcodeblood commented May 16, 2024 reply Follow flag @Shaik Masthan sir actually i was miscalculating the things. Now got it Thanks 0 0 replyShare Please log in or register to add a comment.
10 10 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 1 comment 1 1 comment reply pavansan commented Jan 3, 2025 reply Follow flag yeah thanks for the example got it 0 0 replyShare Please log in or register to add a comment.
2 2 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 0 reply Please log in or register to add a comment.
1 1 vote LET, a=1 ,b=2a=a+ba=3b=a-bb=1a=a-ba=2 a=2b=1 so this programme swap the value of a and b rohitmewada947 answered Sep 2, 2025 rohitmewada947 comment Share Follow 0 reply Please log in or register to add a comment.