bool to int cast

M

MathWizard

Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?

Jeroen
 
R

Robert Bauck Hamar

MathWizard said:
Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?

No, int(true) is always 1. And int(false) is always 0.
 
J

Jim Langston

MathWizard said:
Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?

From bool to int, false is always 0, true is always 1.
From int to bool, 0 is always false, anything other than 0 is true.
 
J

Jojo

Jim Langston schreef:
From bool to int, false is always 0, true is always 1.
From int to bool, 0 is always false, anything other than 0 is true.
OK, thanks guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top