C Language implementation BOOL type

Source: Internet
Author: User

BOOL evaluates to FALSE and true, which is the difference between 0 and 1, and false can represent 0, but true has many kinds. Not only 1. BOOL is a type of definition in C + +, how do we implement bool type data in C?

We can do this with the definition of an enumerated type, which is a way to define constants, which are incremented by default from 01 times, or are self-defined, and undefined portions are incremented.

  1. #include  <stdio.h> &NBSP;&NBSP;
  2. #include <stdlib.h>   
  3. typedefenum {false= 0,true= 1}BOOL;//Use enum type to define BOOL  
  4. int Main ()
  5. {
  6.      int  k=0x0001;   
  7.      bool  i;   
  8.      i= (bool ) K; //convert to BOOL takes last
  9.      printf ( "%d" Span style= "margin:0px; padding:0px; Border:none; Background-color:inherit; " >,i);   
  10.      while (1);   
  11. return  0;
  12. }

C language implementation bool type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.