TipGiver
Programmer
- Sep 1, 2005
- 1,863
Hi,
take a look at this example:
Running it as it is the printf will show 4
Changing '+' to '&&' gives 0.
If i change the f(): x=9, with '+' the result is 4 again.
Can you explain what the '&&' does?
I understand that '&' is for bits, so:
- if x=1, y=2 (binary 01 and 10) then x & y gives 0.
- ... same x && y gives 1.
Why ?
Thanks
take a look at this example:
Code:
#include <stdio.h>
int x;
int f()
{
x=0;
return x;
}
int g()
{
x=4;
return x;
}
void main()
{
[b](void)(f() + g());[/b]
printf("%d\n",x);
}
Running it as it is the printf will show 4
Changing '+' to '&&' gives 0.
If i change the f(): x=9, with '+' the result is 4 again.
Can you explain what the '&&' does?
I understand that '&' is for bits, so:
- if x=1, y=2 (binary 01 and 10) then x & y gives 0.
- ... same x && y gives 1.
Why ?
Thanks