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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top