Home > Software design >  What is the definition of "single statement" in C ?
What is the definition of "single statement" in C ?

Time:01-19

Identify a statement that is false for the given snippet:

int n = 1   2;

A. 1 and 2 are operands.

B. is operator.

C. ; marks the end of a statement in C .

D. It is a single statement.

CodePudding user response:

The answer is C.

while (false){}, for example, is a statement that does not require a semicolon.

You can even write an entire program in C without a semicolon:

#include <iostream>
int main()
{
    if (std::cout << "Hello World"){
    }
    // returning zero is implicit in main
}

Although really, knowing this is not going to make you a better C programmer. Contributing to open source projects or getting a job in the field would.

CodePudding user response:

The answer is C.

The grammar production for a for statement is

for ( init-statement conditionopt ; expressionopt ) statement

So, in

for (int i = 0; i < 10;   i)

the first ; ends the "init-statement". The second ; is part of the for loop grammar, and does not end a statement.

  •  Tags:  
  • Related