这是正确的C声明吗?如果是这样,为什么它不起作用? [英] Is this proper C declaration? If so, why does it not work?

查看:76
本文介绍了这是正确的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.

这篇关于这是正确的C声明吗?如果是这样,为什么它不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆