Jump to content

true

- - - - -

  • Please log in to reply
3 replies to this topic

#1
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
hi
Are
true
and
false
literal constants?!
I wrote this ebook! Will you translate it into English for free!?:confused: PM me!

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
In C++, yes. In C, they are typically implemented as enumerations of 1 and 0, respectively.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
kernelcoder

kernelcoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 282 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal
In C++, yes. In C, I just tried with the statement 'while(true);' with msvc compiler and got an compiling error "Error C2065: 'true' : undeclared identifier in 'somefile.c'".

So in C, to use true/false, you need to follow any of the two ways.

// Way 1
#define true 1
#define false 0

//Way 2
enum {false, true};


#4
icoheed

icoheed

    Newbie

  • Members
  • Pip
  • 2 posts
  • Location:México D.F
  • Programming Language:C, Java, PHP, Ruby
  • Learning:Objective-C, Python, JavaScript
@kernelcoder is right, but in C language you can also use boolean variables to implement the true or false condition. If you check into Stdbool.h header it may be a solution.
Once you dive into programming world, your will not be the same as yesterday.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users