这是正确的C声明吗?如果是这样,为什么它不起作用?

这是正确的C声明吗?如果是这样,为什么它不起作用?

问题描述:

我正在从一本教育书籍编写演示程序,该教育书籍是为Unix和Windows讲授 C而编写的。但是,有时我遇到的代码在正确键入时不想工作。

I'm writing a demo program from an educational book made to teach "C" for Unix and Windows. However, sometimes I come across code that, when typed exactly, does not want to work.

例如。

#include <stdio.h>

int main()

{
    /*This next line is the error */

    int num = 2, bool = 0;

    if ( (num==2) && (!bool) )
    {
         printf("The first test is untrue\n");
    }
    else if( (num==2) && (!bool) )
    {
         printf("The second test is true\n");
    }
    else if( (num==2) && (bool==0) )
    {
         printf("The third test is true - but unreached\n");
    }
    return 0;
}

无论如何,就像我在标题中提到的那样,我很好奇我是否拥有这些正确声明的变量。我使用的是Windows操作系统(7)。

Anyway, like I mentioned in the title, I am curious if I have these variables declared properly. I am using a windows OS (7).

使用C编译器时,不会出现错误,因为 bool 在C中既不是类型也不是保留字。

With a C compiler, there shouldn't be an error because bool is neither a type nor a reserved word in C.

使用C ++编译器,您可能会得到解析错误。

With a C++ compiler, however, you will probably get a parsing error.