Thread: FALSE AND TRUE in C language

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    FALSE AND TRUE in C language

    Hi guys !
    the teacher once I learned the C programming language just said like this : if (false) then we aren't entering the block of "if", but once if(true) then it enters the block statement of "if", my question is why really the PC works like this, I mean why actually "if (false) " then the PC wouldn't enter the if statement .. ? I can just say it's like that moded .. but how it's translated "false" to PC and why it leads him to not entering the if statement? .. for instance why at "if(true)" the pc actually enters the if statement other than not choosing the choice "not entering it"? why "if (true)" doesn't mean for instance "not entering the block statement" ?!

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,859
    false => 0
    true => everything else.

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    499
    Simple answer: LOGIC.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,070
    Quote Originally Posted by RyanC
    why "if (true)" doesn't mean for instance "not entering the block statement" ?!
    Because the people who came up with that language feature weren't as prone to overthinking and confusing themselves as you are.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2019
    Posts
    209
    RyanC, the mystery you're probing is found by knowing assembler, and how the CPU operates. It is rather primitive, which means writing to the CPU in it's own language is rather detailed, tedious and uncomfortable.

    C was created, originally, for the purpose of writing an operating system. That operating system had already been written in assembler, for a particular CPU. C was intended to function in place of that assembler, without any direct reference to any particular CPU (which means for any CPU).

    As a result, the language does have certain technical association with assembler, and I've found knowing assembler to be enlightening on questions just like you've posed.

    However, I come from a different era, the '70's and 80's. Although I've kept my skills very current, my own early study naturally involved more primitive hardware and primitive languages. It may not be as practical today.

    If you were a serious student and not merely curious, I might recommend a tour of assembler.

    Otherwise, however, I'm convinced such things will remain a mystery.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    @Niccolo, RyanC is our resident troll - who was banned for a while.
    He's been here 4.5 years, but hasn't learnt anything.
    Next thing he'll be worrying about is how electrons "know" whether to go through a transistor gate or not.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by Salem View Post
    @Niccolo, RyanC is our resident troll - who was banned for a while.
    He's been here 4.5 years, but hasn't learnt anything.
    Next thing he'll be worrying about is how electrons "know" whether to go through a transistor gate or not.
    just to laugh
    the electrons wouldn't go to the transistor gate if there was
    an equal potential between Drain and source xD

  8. #8
    Banned
    Join Date
    Apr 2015
    Posts
    596
    I don't know if I'm stupid that much or you guys trying to make me stupid ..
    if a programmer doesn't know actually why if (true) then the PC enters the if statement and why for isntance if (true) not actually choosing the choice "not entering the statement" .. then wouldn't be a good programmer ..

    where's the problem? I want to know why is that true .. I can't everything say "yes it's like this ..that's not learning ... we are not in learning medicine this as this .. "

  9. #9
    Banned
    Join Date
    Apr 2015
    Posts
    596
    My question is really explicitly asked .. why actually "true" correspond to satisfying what's found inside if statement .. why actually not the opposite .. not doing the if statement by putting "true" inside if?

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    Closed another RAFB thread.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,070
    Quote Originally Posted by RyanC
    why actually not the opposite .. not doing the if statement by putting "true" inside if?
    Tell you what: if you pay me $100, then I will transfer ownership of my house to you.

    Of course, when you pay me $100, I will then tell you: it is true that you've paid me $100, therefore I will not transfer ownership of my house to you. Thanks for the $100, RyanC!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. True or False
    By camel-man in forum C Programming
    Replies: 9
    Last Post: 02-14-2013, 01:27 AM
  2. true or false
    By johngav in forum C Programming
    Replies: 4
    Last Post: 03-19-2009, 02:25 PM
  3. True / False
    By goran00 in forum C Programming
    Replies: 13
    Last Post: 03-14-2008, 03:26 PM
  4. true/false
    By goran00 in forum C Programming
    Replies: 18
    Last Post: 03-12-2008, 10:40 AM
  5. Help with True, False, NOT, AND, OR...
    By cgsarebeast in forum C++ Programming
    Replies: 22
    Last Post: 05-09-2006, 07:59 PM

Tags for this Thread