What does 1 & mean

I know that the & before a variable is a reference to another variable. What does & mean in an if statement.
Specifically this one:
if (token[0] == '(' & token[1] == '\0')
closed account (zb0S216C)
You mean bit-wise AND? Here's a link: http://msdn.microsoft.com/en-us/library/z0zec0b2(v=vs.71).aspx

Wazzak
I understand this expression

0 1 0 1 // 5
0 1 1 0 // 6
--------
0 1 0 0 // 4

but how would this work in the context of evaluating an if statement. Since if statements evaluate to true or false it seems like the logical 'and' operator should be there instead.
I think that you are trying to say 'AND' operator. Well if you thought that then you wrote it wrong. Try replacing your ampersand with this '&&' two ampersands. And i really think you thought of and, because your ampersand is totally wrong.
I didn't write it wrong because I got it from someone else's source code.
http://www.speqmath.com/tutorials/expression_parser_cpp/index.html
parser.cpp

To put it into a bigger context:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// check if it is a parenthesized expression
    if (token_type == DELIMETER)
    {
        if (token[0] == '(' & token[1] == '\0')
        {
            getToken();
            double ans = parse_level2();
            if (token_type != DELIMETER || token[0] != ')' || token[1] || '\0')
            {
                throw Error(row(), col(), 3);
            }
            getToken();
            return ans;
        }
    }
Okay i don't care who you wrote that code from. Just add double ampersands. Because the person you got the code from made a tiny mistake or was very high.
closed account (zb0S216C)
Happykiller, we don't know the authors reason for using the bit-wise AND. And for all we know, the bit-wise AND could be intentional, or it could be a simple mistake.

Wazzak
& with bools as the operands behaves like &&, except that there is no short-circuit behavior.
Thx Athar for clearing things up.

Any reason for using the non short-circuit version of AND?
You can use it when your operands have side effects and you need to make sure that all of them are carried out.
You'll get no implicit conversion to bool with &, so using it for that purpose is best avoided.
Thx. That helps a lot
Topic archived. No new replies allowed.