Settled

I'll take my chances with C types & operators, Sir

The C Programming Language — Chapter 2 Brian W. Kernighan & Dennis M. Ritchie → Oct 21, 2026 ~9 min read

variable · constant · limits.h · floats.h · ctype.h · sign extension · truncation · string literal · string constant · #define · enum · wraparound · cast · two's complement · ones' complement · hexadecimal · octal · binary · EBCDIC · ASCII · static typing · dynamic typing · type inference · machine dependence · null terminator · automatic variable · integer division · truncation · overflow · underflow · short circuit · propositional logic · type conversion · cast · prefix · postfix · bitwise operators · arithmetic operators · arithmetic shift · logical shift · mask · getbits · ASCII arithmetic · hexadecimal · place value · precedence · software metrics

This post is more of a cheat sheet for rules and quirks in C type, operators and expressions. The companion post is K&R Chapter 2: Do you fear operators?. No narrative here, just the rules.

Variable names

Basic types

TypeNotes
chara single byte, holds one character in the local character set
intan integer, typically the natural word size of the machine
floatsingle-precision floating point
doubledouble-precision floating point

Qualifiers

Constants

Declarations and initialization

Arithmetic operators

Relational and logical operators

Type conversions

Increment and decrement

Bitwise operators

Applicable only to integral operands.

OperatorMeaning
&bitwise AND
|bitwise inclusive OR
^bitwise exclusive OR
<<left shift
>>right shift
~one’s complement (unary)

Idiom: extract a bit field

/* getbits: get n bits from position p */
unsigned getbits(unsigned x, int p, int n) {
  return (x >> (p+1-n)) & ~(~0 << n);
}

Assignment operators

Conditional expression

Precedence and associativity

Highest to lowest:

OperatorsAssociativity
() [] -> .left to right
! ~ ++ -- + - * & (type) sizeofright to left
* / %left to right
+ -left to right
<< >>left to right
< <= > >=left to right
== !=left to right
&left to right
^left to right
|left to right
&&left to right
||left to right
?:right to left
= += -= and the restright to left
,left to right

Order of evaluation

What the language does not promise:

Machine-dependent behaviour, quick list

Everything in this chapter that can differ between machines or compilers:

Related posts

← Back to all posts