Tutorial by Examples

Relational operators check if a specific relation between two operands is true. The result is evaluated to 1 (which means true) or 0 (which means false). This result is often used to affect control flow (via if, while, for), but can also be stored in variables. Equals "==" Checks whether...
Assigns the value of the right-hand operand to the storage location named by the left-hand operand, and returns the value. int x = 5; /* Variable x holds the value 5. Returns 5. */ char y = 'c'; /* Variable y holds the value 99. Returns 99 * (as the character 'c' is repr...
Basic Arithmetic Return a value that is the result of applying the left hand operand to the right hand operand, using the associated mathematical operation. Normal mathematical rules of commutation apply (i.e. addition and multiplication are commutative, subtraction, division and modulus are not). ...
Logical AND Performs a logical boolean AND-ing of the two operands returning 1 if both of the operands are non-zero. The logical AND operator is of type int. 0 && 0 /* Returns 0. */ 0 && 1 /* Returns 0. */ 2 && 0 /* Returns 0. */ 2 && 3 /* Returns 1. */ Lo...
The increment and decrement operators exist in prefix and postfix form. int a = 1; int b = 1; int tmp = 0; tmp = ++a; /* increments a by one, and returns new value; a == 2, tmp == 2 */ tmp = a++; /* increments a by one, but returns old value; a == 3, tmp == 2 */ tmp = --b; ...
Evaluates its first operand, and, if the resulting value is not equal to zero, evaluates its second operand. Otherwise, it evaluates its third operand, as shown in the following example: a = b ? c : d; is equivalent to: if (b) a = c; else a = d; This pseudo-code represents it : c...
Evaluates its left operand, discards the resulting value, and then evaluates its rights operand and result yields the value of its rightmost operand. int x = 42, y = 42; printf("%i\n", (x *= 2, y)); /* Outputs "42". */ The comma operator introduces a sequence point between i...
Performs an explicit conversion into the given type from the value resulting from evaluating the given expression. int x = 3; int y = 4; printf("%f\n", (double)x / y); /* Outputs "0.750000". */ Here the value of x is converted to a double, the division promotes the value of...
With a type as operand Evaluates into the size in bytes, of type size_t, of objects of the given type. Requires parentheses around the type. printf("%zu\n", sizeof(int)); /* Valid, outputs the size of an int object, which is platform-dependent. */ printf("%zu\n", sizeof int); ...
Pointer addition Given a pointer and a scalar type N, evaluates into a pointer to the Nth element of the pointed-to type that directly succeeds the pointed-to object in memory. int arr[] = {1, 2, 3, 4, 5}; printf("*(arr + 3) = %i\n", *(arr + 3)); /* Outputs "4", arr's fourth e...
The member access operators (dot . and arrow ->) are used to access a member of a struct. Member of object Evaluates into the lvalue denoting the object that is a member of the accessed object. struct MyStruct { int x; int y; }; struct MyStruct myObject; myObject.x = 42; myObj...
The first operand must be a function pointer (a function designator is also acceptable because it will be converted to a pointer to the function), identifying the function to call, and all other operands, if any, are collectively known as the function call's arguments. Evaluates into the return valu...
Bitwise operators can be used to perform bit level operation on variables. Below is a list of all six bitwise operators supported in C: SymbolOperator&bitwise AND|bitwise inclusive OR^bitwise exclusive OR (XOR)~bitwise not (one's complement)<<logical left shift>>logical right shift...
C11 Queries the alignment requirement for the specified type. The alignment requirement is a positive integral power of 2 representing the number of bytes between which two objects of the type may be allocated. In C, the alignment requirement is measured in size_t. The type name may not be an inco...
Short circuiting is a functionality that skips evaluating parts of a (if/while/...) condition when able. In case of a logical operation on two operands, the first operand is evaluated (to true or false) and if there is a verdict (i.e first operand is false when using &&, first operand is tr...

Page 1 of 1