C Operators/Expressions


Operators are used with operands to build expressions. For example the following is an expression containing two operands and one oprator.

        4 + 5
The following list of operators is probably not complete but does highlight the common operators and a few of the outrageous ones....

C contains the following operator groups.

The order (precedence) that operators are evaluated can be seen here.

Arithmetic

        +
        -
        /
        *
        %       modulo
        --      Decrement (post and pre)
        ++      Increment (post and pre)

Assignment

These all perform an arithmetic operation on the lvalue and assign the result to the lvalue. So what does this mean in English? Here is an example:
   counter = counter + 1; 
can be reduced to
   counter += 1;           
Here is the full set.
        =
        *=      Multiply
        /=      Divide.
        %=      Modulus.
        +=      add.
        -=      Subtract.
        <<=     left shift.
        >>=     Right shift.
        &=      Bitwise AND.
        ^=      bitwise exclusive OR (XOR).
        |=      bitwise inclusive OR.

Logical/Relational

        ==      Equal to
        !=      Not equal to
        >
        <
        >=
        <=
        &&      Logical AND
        ||      Logical OR
        !       Logical NOT

Bitwise

        &       AND (Binary operator)
        |       inclusive OR
        ^       exclusive OR
        <<      shift left. C ++ use of <<

        >>      shift right. C ++ use of >>
        ~       one's complement

Odds and ends!

        sizeof() size of objects and data types.
                 strlen may also be of interest.
        &       Address of (Unary operator)
        *       pointer (Unary operator)
        ?       Conditional expressions
        :       Conditional expressions
        ,       Series operator.

C++ Extensions

Read about :: >> and << in the world of C++ here!

Top Master Index Keywords Functions


Martin Leslie
tion>space:mode:
authorJohannes Berg <johannes.berg@intel.com>2017-02-07 10:40:50 +0100
committerJohannes Berg <johannes.berg@intel.com>2017-02-07 10:40:50 +0100
commitbddb2afcb6c52a545f18fb9bcd4829828ebf4a3a (patch)
tree0021fe481f8acf3694d92d72f3dd1b2a71a20ca3 /tools/testing/selftests/bpf
parent228c8c6b1f4376788e9d5ab00d50b10228eb40d3 (diff)
mac80211: add back lost debugfs files
Somehow these files were never present or lost, but the code is there and they seem somewhat useful, so add them back. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'tools/testing/selftests/bpf')