C Programming: Memory, Pointers and the Stack ยท Control Flow
Choose a branch with if / else if / else, and match exact values with switch, where break matters.
#include <stdio.h>
int main(void) {
int temp = 31;
const char *feel;
if (temp > 30) {
feel = "hot";
} else if (temp > 15) {
feel = "mild";
} else {
feel = "cold";
}
int day = 2;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
default:
printf("Another day\n");
}
printf("%s\n", feel);
return 0;
}temp is created on the stack with the value 31. feel is created on the stack with the value ?.feel changes from ? to "hot".day is created on the stack with the value 2.Tuesday.hot.0.