Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Industrial programming >> C Taal

C-operators: Types, functies en voorbeelden

Overzicht operatorcategorieën

  • Rekundige (arithmetic)
  • Relationele (relational)
  • Logische (logical)
  • Bitwise
  • Toewijzing (assignment)
  • Diverse (sizeof, ternary, adres, dereferentie)

Rekundige operators

OpBeschrijvingVoorbeeld (A=10, B=20)
+OptellenA + B = 30
-AftrekkenA - B = -10
*VermenigvuldigenA * B = 200
/Delen (integer deling als beide int)B / A = 2
%Modulo (rest)B % A = 0
++IncrementA++ = 11
--DecrementA-- = 9

Relationele operators

OpBeschrijvingVoorbeeld (A=10, B=20)
==Gelijk aan(A == B) is false
!=Niet gelijk(A != B) is true
>Groter dan(A > B) is false
<Kleiner dan(A < B) is true
>=Groter of gelijk(A >= B) is false
<=Kleiner of gelijk(A <= B) is true

Logische operators

OpNaamBeschrijvingVoorbeeld (A=1, B=0)
&&Logical ANDBeide non-zero → true(A && B) is false
||Logical ORÉén non-zero → true(A || B) is true
!Logical NOTKeert logische waarde om!(A && B) is true

Bitwise operators

Werken op bitniveau. Waarden: A=60 (0011 1100), B=13 (0000 1101).

OpNaamResultaatBinair
&AND120000 1100
|OR610011 1101
^XOR490011 0001
~One's complement-611100 0011
<<Left shift2401111 0000
>>Right shift150000 1111

Toewijzingsoperators

OpEquivalent
=C = A + B
+=C = C + A
-=C = C - A
*=C = C * A
/=C = C / A
%=C = C % A
<<=C = C << 2
>>=C = C >> 2
&=C = C & 2
^=C = C ^ 2
|=C = C | 2

Diverse operators

OpBeschrijvingVoorbeeld
sizeof()Grootte in bytessizeof(int) → 4
&Adres-van (address-of)&a
*Dereferentie (pointer)*ptr
? :Ternaire (conditionele) operatormax = (a>b) ? a : b
,Komma-operator (sequentieel evalueren)a = (b=3, b+2)

Operator-precedentie (van hoog naar laag)

CategorieOperatorsAssociativiteit
Postfix() [] -> . ++ --Links→rechts
Unair+ - ! ~ ++ -- (type)* & sizeofRechts→links
Multiplicatief* / %Links→rechts
Additief+ -Links→rechts
Shift<< >>Links→rechts
Relationeel< <= > >=Links→rechts
Gelijkheid== !=Links→rechts
Bitwise AND&Links→rechts
Bitwise XOR^Links→rechts
Bitwise OR|Links→rechts
Logical AND&&Links→rechts
Logical OR||Links→rechts
Conditioneel?:Rechts→links
Toewijzing= += -= *= /= %= >>= <<= &= ^= |=Rechts→links
Komma,Links→rechts

Voorbeeld: x = 7 + 3 * 2 → x = 13 (niet 20), want * bindt sterker dan +.

C Taal

  1. C# Operators – Uitgebreide gids voor operators in C#
  2. C# Bitwise en Bit Shift Operators: Een Uitgebreide Gids
  3. C++ operators: complete gids met praktische voorbeelden
  4. C Programmeeroperatoren Beheersen: Een Uitgebreide Gids
  5. Bitwise Operatoren in C Beheersen: AND, OR, XOR, Shifts & Complement
  6. Uitgebreide Gids voor C++ Operators: Types, Gebruik en Best Practices
  7. Verilog operatoren: Essentiële rekenkundige & controle operatoren voor synthetise
  8. MATLAB Operatoren: Complete Gids voor Rekenkundige, Logische en Bitwise Operaties
  9. Python Operators onder de knie krijgen: Een uitgebreide gids
  10. Java-operators beheersen: typen, syntax en praktische voorbeelden
  11. Java Essentials: Uitgebreide Gids voor Kern Operators