GATE C Programming formula sheet
17 formulas in 3 topics, each with when to use it. Each is explained in the topic notes.
Print the whole sheetN-BIT INTEGER RANGES
Holds for any fixed-width integer type once its width in bits and its signedness are known. Use it to check whether a constant fits the type it is stored in.
STORING AN OUT-OF-RANGE VALUE V IN A SIGNED N-BIT TYPE
The standard leaves this conversion implementation-defined. On the two's complement machines these notes assume, the result is the value above. For example, 200 stored in a signed 8-bit char gives . An unsigned -bit type always stores , and that case is defined by the standard.
1-D ARRAY INDEXING / POINTER ARITHMETIC
For any array a with element type T. The same value is the address a + i. C arrays always start at index 0, and memory is byte-addressable.
2-D ROW-MAJOR ADDRESS (C ARRAYS)
The array is declared T a[R][C]. C is the number of COLUMNS (the row length), i is the row index and j is the column index, both starting at 0. The number of rows R does not appear.
CALL COUNT: SINGLE (LINEAR) RECURSION
For a function that makes exactly one recursive call, on , and stops at n == 0 without a further call (for example, a factorial with base case n == 0). counts the initial call and the base-case call. If the base case is at n == 1 instead (with ), the count is . Always check where the base case fires.
CALL COUNT: HALVING RECURSION
For a function that makes one recursive call on n / 2 (integer division) and stops at n == 0, like bin above. The calls that print or do work (those with ) number , which is the number of bits of . The extra call is the base case n == 0.