1. 程式人生 > >面試——c語言定義bool型別

面試——c語言定義bool型別

C語言自定義bool型別的兩種方式

由於C語言以0,1分別代表false,true,

可以自定義bool型別,這裡有兩種方式作為參考:

1:定義列舉型別:typedef enum{false,true} bool;


2:也可以使用預定義

#ifndef bool
#define bool int
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif


原文:https://blog.csdn.net/qq387732471/article/details/696895