warning: suggest parentheses around assignment used as truth value [-Wparentheses]

今天在学习——校门外的树

写code的时候报错:
warning: suggest parentheses around assignment used as truth value [-Wparentheses]

警告:建议将赋值周围的括号用作真值

下面是错误之处:

    for(int i=0;i<=L;i++){
        if(tree[i]=true){  //错误指向
            count++;
        }
    }
在C语言中,非0代表TRUE,反之为FALSE
atype值是用于最后的判断用的,但是由于长期的编程实践告诉我们
人们经常在"="和“==”的使用上出现手误
所以gcc编译器要求我们明确地告诉编译器它是"="而不是"=="
是故意,而非手误

想在判断语句中使用“=”时,要加上括号:

    for(int i=0;i<=L;i++){
        if((tree[i]=true)){  
            count++;
        }
    }
发布了59 篇原创文章 · 获赞 10 · 访问量 5490

猜你喜欢

转载自blog.csdn.net/qq_43476433/article/details/104144582
今日推荐