#include<stdio.h>
#include<conio.h>
int main(){
int a,b;
a = -3- -3;
b = -3 - - (-3 );
printf("%d %d",a,b);
getch();
return 0 ;
}
the ouput is -6 and 0.Please explain how?
|
Mentor
|
![]() |
| 30Jul2012,00:13 | #2 |
|
Compiler bug probably. (-3) - (-3)=0 because any finite number minus itself is zero, so if your compiler thinks this is -6 then it's wrong. Similarly (-3) - -(-3) = (-3) - (3) = -6, not 0.
The answers are correct though, if transposed, so if the output is 0 -6 then that's correct. -6 0 would be wrong. To make certain, split the output with more detail to be sure: Code:
printf("(-3) - (-3) = %d\n",a);
printf("(-3) - -(-3) = %d\n",b);
Code:
void test49()
{
int a,b;
a = -3- -3;
b = -3 - - (-3 );
printf("%d %d\n",a,b);
printf("-3- -3=%d\n",a);
printf("-3 - - (-3 )=%d\n",b);
}
Code:
0 -6 -3- -3=0 -3 - - (-3 )=-6
state
like this
|
|
Go4Expert Member
|
|
| 30Jul2012,15:14 | #3 |
|
Sorry i mistyped the answer.Thank you for replying.
|

