Expression Versus Statement

前端 未结 21 2037
别那么骄傲
别那么骄傲 2020-11-22 11:54

I\'m asking with regards to c#, but I assume its the same in most other languages.

Does anyone have a good definition of expressions and statements

21条回答
  •  攒了一身酷
    2020-11-22 12:20

    A statement is a block of code that doesn't return anything and which is just a standalone unit of execution. For example-

    if(a>=0)
    printf("Hello Humen,I'm a statement");
    

    An expression, on the other hand, returns or evaluates a new value. For example -

     if(a>=0)
        return a+10;//This is an expression because it evalutes an new value;
    

    or

     a=10+y;//This is also an expression because it returns a new value. 
    

提交回复
热议问题