Thread: Help plz, Booleans

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    1

    Question Help plz, Booleans

    i dont like spamming & im sure theres a post with this exact same question 100 times over but right now im 2 lazy to look, ty.

    What are these comparing to?

    Code:
    A. !( 1 || 0 )                ANSWER: 0	
    B. !( 1 || 1 && 0 )       ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 )  ANSWER: 1 (Parenthesis are useful)
    Im learning c++ & from what i understand you are supossed to do a comparison of some kind then compare the comprisons:

    Code:
    (!(1==0) && 0+1 > 0)   ANSWER: false
    but up above it returns integers rather than a simple true or false, can someone explain this to me?

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    i'm too lazy to give you the answer



    [edit]

    i lied. i performed the search for you. total time: less than 10 seconds. here is the answer

    http://cboard.cprogramming.com/showt...light=booleans

    [/edit]
    Last edited by The Brain; 07-25-2005 at 07:11 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by tagman
    Code:
    (!(1==0) && 0+1 > 0)   ANSWER: false
    but up above it returns integers rather than a simple true or false, can someone explain this to me?
    not sure what you mean here, if you are expecting the output of the words "true" or "false" then don't hold your breath. bool is an intergral type and only outputs 0 or 1 which technically are intergers but internally they are actually type bool and you will get a warning if you try to compare/use them as integers. For example Windows redfines integer as BOOL to use as bools, but they ARE integers. C++ defines a bool which is an integral type but is not an integer thus:

    Code:
    #include <iostream>
    #include "windows.h"
    using namespace std;
    
    
    int main()
    {
    	BOOL window_bool = TRUE; //TRUE is defined in windows as the integer 1;
    
    	bool cplusplus_bool = true; // true here is a built in constant (?) of type bool
    
    	if (window_bool == cplusplus_bool)
    	{
    		//...dosomething
    	}
    }
    gives this warning:

    warning C4805: '==' : unsafe mix of type 'BOOL' and type 'bool' in operation

    changing it to: int window_bool, gives the same warning

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  4. plz help me fix this problem
    By Joe100 in forum C++ Programming
    Replies: 8
    Last Post: 07-13-2003, 01:25 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM