简体   繁体   English

没有 arguments 的 if == 语句会发生什么情况?

[英]what happens with if == statement with no arguments?

With

if (i==1) {something} - program will execute something on true if (i==1) {something} - 程序将在 true 上执行某事

what happens with发生了什么

if (i==1) - will it break or do nothing on false? if (i==1) - 它会破坏还是什么都不做?

I've seen program with我看过程序

if (id == 0x11) //OK if (id == 0x11) //确定

with no {} and don't know if it does something.没有 {} 并且不知道它是否做了什么。 I think it should use next line as its "insides" but it wouldn't change anything我认为它应该使用下一行作为它的“内部”,但它不会改变任何东西

The next statement will be used as the if block.下一条语句将用作 if 块。 Opening brace does not necessarily be on the same line with the if, and a single statement if does not need to use opening and closing braces.左大括号不一定与 if 在同一行,单条语句 if 不需要使用左大括号和右大括号。 All of the following are equivalent:以下所有内容都是等效的:

if (expression) // OK
{
    statement1;
}

if (expression) { statement1;}

if (expression)
    statement1;

The syntax is ( C11 6.8.4 )语法是( C11 6.8.4

if (<condition>) <statement>

where <condition> is some expression with a value compatible to int其中<condition>是某个表达式,其值与int兼容
and
<statement> is a regular statement or a block statement. <statement>是常规语句或块语句。

if (foo == 42) return 4; // regular statement ends with semicolon
if (bar == foo) { puts("nope!"); exit(EXIT_FAILURE); } // block statement

And, remember that whitespace is not significant in C text source而且,请记住,空格在 C 文本源中并不重要

if (a == b)

b = 0;

is equal to等于

if (a == b) b = 0;

If condition was false statements with in if condition were not executed..如果条件是假的语句,如果条件没有执行..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM