// assignment a = 1; a = -2; a = (1 + (2 * (3 / 4))); a = foo(); a = bar(1); a = baz(1, 2, (1 + 1), foo(), bar(1)); a = "I said \"Hello\" to the baker."; // declaration assignment int a; int a = 3; float a = -3.14159; bool a = true; bool a = false; char *a = "hello, world!"; // assignment operators a = a; a += a; a -= a; a *= a; a /= a; a %= a; a &= a; a |= a; a ^= a; a <<= a; a >>= a; // unary operators a = -(a); a = &(a); a = *(a); a = !(a); a = ~(a); a = !(!(a)); // binary operators a = (a + a); a = (a - a); a = (a * a); a = (a / a); a = (a % a); a = (a == a); a = (a != a); a = (a < a); a = (a > a); a = (a <= a); a = (a >= a); a = (a && a); a = (a || a); a = (a & a); a = (a | a); a = (a ^ a); a = (a << a); a = (a >> a); // return return; return 1; return a; return (1 + 1); return foo(1, (2 + 3), bar(1)); // funcalls foo(); foo(1); foo(foo(1)); foo(1, (2 + 3), foo(), foo(1, 2)); // scopes { return; } { return; a = 1; } { int a = 1; a += 1; } { int b = (1 + foo()); { float c = -1.1; return b; } } // function declaration void foo() { return; } bool* foo(int a, char *b) { float c = -1.1; return (c + 1); } int main(int argc, char **argv) { int a = foo(); float b = ((foo() + foo()) / foo()); if (1) { return a; } else { if ((1 + 1)) { char z = "z"; } else if (foo()) { return; } else { foo(); } } } // while loops while (1) { break; } while (true) { a += 1; if ((a > 42)) { break; } else { a += 2; continue; } } // for loops for ( (i < 1); i += 1) { continue; } for (i = 2; (i < 42); i += 2) { sideEffect(); } for (int i = 0; (i < len(things)); i += 1) { if ((i == 0)) { continue; } else { sideEffect(); } } // this is a line-level comment /* this is a block-level comment */ /* * This is a * multi-line * block-level * comment. */ // include directives #include <foo.h> #include <dir/foo.h> #include "foo.h" #include "dir/foo.h" #include "/dir/foo.h" #define FOOS 1 #define debug(m,e) printf("%s:%d: %s:",__FILE__,__LINE__,m); print_obj(e,1); puts(""); // structs typedef struct _struct_foo foo; struct _struct_foo { int bar; }; // self-referential struct typedef struct _struct_list_t list_t; struct _struct_list_t { char *value; list_t *next; }; // dotted access a = a.b; a = a.b.c.d; // dotted assignment a.b = a; a.b.c.d = a; a.b.c = a.b.c; // arrow access a = a->b; a = a->b->c; // arrow assignment a->b = a; a->b->c = a; a->b->c = a->b->c; // indexing a = a[0]; a = a[1][2]; a = a[(1 + 2)]; a[0] = 1; a[0][1] = a[2][3]; // pointer assignment *(a) = 1; *(*(a)) = 1; *(cast(a, int*)) = 1; *((cast(a, int*) + 1)) = 1; *((a + 1)) = 1; *(a->b) = 1; *((a->b + 1)) = 1; *(a.b) = 1;