What is considered a statement in C ++?

My professor usually asks my class how many statements there are in a given program, but I cannot determine what he defines as an instruction. It seems that if / else is one statement, and the for loop is one statement, regardless of whether other alleged statements exist in it. Are there any guidelines for this issue or its definition of his own invention?

thank

+3
source share
4 answers

For an exact definition:

Definition: An operator is a block of code that does something. The assignment operator assigns a value to a variable. The for statement executes a loop. In expressions, C, C ++ and C # can be grouped together as a single statement using curly braces

{  statement1;  2;  }

, , . (LOC) , LOC . , LOC, .

+3

, .. , . , " ", . . , "" .

+1

In computer programming, a statement can be considered the smallest autonomous element of an imperative programming language. A program formed by a sequence of one or more applications. A statement will have internal components (e.g. expressions).

More in the statement (Computer Science) on Wikipedia .

0
source

Here is a function that handles parsing statements in JS:

static void do_statement(CsCompiler *c )
{
    int tkn;
    switch (tkn = CsToken(c)) {

    case T_IF:          do_if(c);       break;
    case T_WHILE:       do_while(c);    break;
    case T_WITH:        do_with(c);     break;
    case T_DO:          do_dowhile(c);  break;
    case T_FOR:         do_for(c);      break;
    case T_BREAK:       do_break(c);    CsSaveToken(c,CsToken(c)); break;
    case T_CONTINUE:    do_continue(c); CsSaveToken(c,CsToken(c)); break;
    case T_SWITCH:      do_switch(c);   break;
    case T_CASE:        /*do_case(c);*/    CsParseError(c,"'case' outside of switch");  break;
    case T_DEFAULT:     /*do_default(c);*/ CsParseError(c,"'default' outside of switch");  break;
    case T_RETURN:      do_return(c);   break;
    case T_DELETE:      do_delete(c);   break;
    case T_TRY:         do_try(c);      break;
    case T_THROW:       do_throw(c);    break;
    case '{':           do_block(c, 0); break;
    case ';':           ;               break;
    default:  
      {
        CsSaveToken(c,tkn);
        do_expr(c);
        break;
      }
    }
}

As you can see, this includes things such as for, whileas well as expressions (separated ;)

0
source

All Articles