Following section about expressions
This commit is contained in:
parent
f18c9ef2e6
commit
f90ee39d02
1 changed files with 59 additions and 0 deletions
59
c_modern_approach/Expressions/theory.c
Normal file
59
c_modern_approach/Expressions/theory.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <stdio.h>
|
||||
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();
|
||||
}
|
Loading…
Reference in a new issue