Conversion from bool to int: Guaranteed Values of 0 or 1
A common misconception arises when converting bool values to int. While many compilers appear to store booleans as 0 or 1, the question remains: is this behavior guaranteed?
Question:
Consider the following C code snippet:
int a = 2; bool b = a; int c = 3 + b; // 4 or 5?
What will be the value of c: 4 or 5?
Answer:
Yes, c will always be 4 in C and C.
Explanation:
The above is the detailed content of What is the value of `c` in the following C/C code: `int a = 2; bool b = a; int c = 3 b;`?. For more information, please follow other related articles on the PHP Chinese website!