What is the output of following code.Pls Explain

#include<stdio.h>
int main( )
{
int a,b;
a = -3 - - 25;
b = -3 - - (-3);
printf(“a=%d b=%d\n”,a,b);
return 0;
}

Brother, you should indent the snippet properly.
Let me try to explain it to you, it involves basic mathematics.
Output : a=22 b=-6

In case of ‘a’:-

Step 1 : a = -3 - - 25
Step 2 : a = -3 + 25 ( as -*- is +)
Step 3 : a = 22

In case of ‘b’:-

Step 1 : b = -3 - - (-3)
Step 2 : b = -3 - + 3 ( as -- is +)
Step 3 : b = -3 - 3 ( as -
+ is -)
Step 4 : b = - 6

I hope I was able to make you understand…

4 Likes

ok…but in the second case you combined two minus sign which were seperated by a bracket…was it correct?

Yes, absolutely correct. It’s a very basic rule of algebra and everything follows the natural laws of mathematics. To brush up your skills refer to : http://algebramethods.com/Bracket%20Workbook(3).pdf

3 Likes