Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
What are the values of a and b after the following function is executed, if the values passed are 30 and 50.
void paws(int a, int b) {
a = a + b;
b = a - b;
a = a - b;
System.out.println(a + " , " + b);
}
Answer:
This is a typical swap function without using third variable. Let us analyse –
a = 30 and b = 50
a = a+b ; //so a would be 80
b = a-b; //since a is now 80 it would be 80 – 50 = 30, so b would now have 30
a = a-b;//would be 80 – 30 (as b is now 30) so now a would be 50
so the output of
System.out.println(a+” , “+b) ; would be 50 , 30
C. Sir| Created: 22-Mar-2018 | Updated: 16-Apr-2019|ICSE2015