这几天在学习Linux下的C语言开发。今天要写一个取1到100之间质数的题。可是,当我用bool类型定义变量b,来标记一个数是否为质数时,编译出错。错误信息显示如下:

     'bool' undeclared (first use in this function)
     (Each undeclared identifier is reported only once
     for each function it appears in.)

  在Google在搜了半天,也没不明白。后来,只得请求高手。得到回复,总结于下:

  C语言(或C++)里本身没有bool这种布尔类型。有些编译器可以识别,那也是因为编译器自己定义了bool类型,比如:#define bool int。

  C语言里,一般用整型变量来实现布尔型变量的功能。当用条件语句,如if,进行判断时,值为0时返回false,其它都返回true。

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2021-09-23
  • 2022-02-11
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2022-02-07
  • 2021-07-31
  • 2021-11-27
  • 2022-01-05
  • 2021-08-10
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案