E
E
Eugene Ordinary2016-12-14 23:23:28
Programming
Eugene Ordinary, 2016-12-14 23:23:28

Is it always false == 0, true == 1 in C++?

Will this code always work correctly?

int A[2] = { 3, 5 }, y, z;
bool x = false;
y = A[x]; // y==3
z = A[!x]; // z==5

Are there implementations where it is not true that false == 0, true == 1?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Evgeny Shatunov, 2016-12-14
@evgeniy8086

Everything about this is clear in the standard.
eelis.net/c++draft/conv.prom#6

J
Jony1337, 2016-12-14
@Jony1337

Always in C++ false == 0, true == 1

A
Alexey Gordienko, 2017-01-02
@RdSpclL

false == 0, true != 0

D
Dmitry Alexandrov, 2017-10-23
@jamakasi666

In C++, there are a billion and 1 ways to shoot yourself in the foot or give yourself a headache for a couple of weeks with a small line, and on different compilers this number and cold-blooded tricks vary. For example classic
In, I dug up an ancient funny joke.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question