+ 3
What does single "&" mean in C
6 odpowiedzi
+ 13
Depending on the context, & symbol could represent bitwise AND operator, and it could also represent address-of operator. It depends where and when the symbol is used ...
int n = 12345;
// here & represents bitwise AND operator
printf( "<n> = %d\n<n> & 5 = %d\n", n, ( n & 5 ) );
// here & represents address-of operator
printf( "Address of <n> = %p\n", &n );
(Edited to add code example)
+ 7
But what does "&&" mean in C
+ 6
& is AND bit operator. It check bit by bit if two of them are 1. Else, result of the bit is 0.
Example:
12 = 00001100 (In Binary)
25 = 00011001 (In Binary)
Bit Operation of 12 and 25
00001100
& 00011001
________
00001000 = 8 (In decimal)
Example taken from programiz
+ 6
&& is used in if blocks, for example. It is the logic AND
int num1 = 5;
int num2 = 9;
int num3 = 3;
num1 < num2 -> true
num1 < num3 -> false
(num1 < num2) && (num1 < num3)
true AND false -> false
This operator returns true if the first and the second blocks are true
Did you understand?
+ 5
Ipang really? Post your example so the answer will be more complete
+ 3
Bitwise and