I noticed that in C, my boolean variable somehow gets changed in a way I don't understand.
#include <stdio.h>
#include <stdbool.h>
int main(void) {
bool x, y;
printf("x: ");
scanf("%d", &x);
printf("x is %d\n", x);
printf("y: ");
scanf("%d", &y);
printf("x is %d\n", x);
printf("y is %d\n", y);
return 0;
}
If I input a value of 1 for x and any value for y (1 in this example):
x: 1 x is 1 y: 1 x is 0 y is 1
at the end, y outputs the correct original value, but x magically changes to 0 in between!
This is not a problem when the input for x is 0 since the outputs for both x and y are their respective original values as expected.
Please explain what is going on!