diff --git a/c_modern_approach/Expressions/theory.c b/c_modern_approach/Expressions/theory.c new file mode 100644 index 0000000..54f8634 --- /dev/null +++ b/c_modern_approach/Expressions/theory.c @@ -0,0 +1,59 @@ +#include +void undefined_subexpression() { + int b, c; + int a = 5; + c = (b = a + 2) - (a = 1); + printf("%d", c); +} + +void comparison_unexpected() { + int i, j, k; + i = 10; + j = 2; + k = 0; + // This is equivalent of (i < j) < k because it is < is left-associated + // operator + printf("\n%d", i < j < k); +} + +void switch_playground() { + int grade = 1; + switch (grade) { + /* case 0: */ + /* printf("Failint"); */ + /* break; */ + /* case 1: */ + /* printf("Poor"); */ + /* break; */ + /* case 2: */ + /* printf("Average"); */ + /* break; */ + /* case 3: */ + /* printf("Good"); */ + /* break; */ + /* case 4: */ + /* printf("Excelent"); */ + /* break; */ + /* default: */ + /* printf("Illegal grade"); */ + /* break; */ + /* } */ + case 0: case 1: case 2: case 3: case 4: + printf("Allowed grades"); + break; + default: + printf("Illegal grade"); + break; + } +} + +int main() { + int i = 5; + float k = 1.1; + float j = 10 * i + k; + printf("%f\n", j); + undefined_subexpression(); + comparison_unexpected(); + printf("\n"); + switch_playground(); +}