Machine-translated by Google. Questions are authored in English.
Top

Discussion

int main() {
    int x
    x = (1 + 2;
    return x;
}

Which of the following statements is true with respect to this source code in C language ?

  • A.Syntax Error
  • B.Semantic Error
  • C.Linking Error
  • D.Runtime Error

Answer: A

The code has a syntax error.

int x lacks the semicolon that ends a declaration, and x = (1 + 2; has an opening parenthesis with no closing one. Both break the grammar of C, so the compiler's parser rejects the program before it is ever linked or run.

A semantic error is grammatically valid code with a wrong meaning, such as a type mismatch. A linking error arises when a referenced function or variable cannot be found. A runtime error occurs while a compiled program runs. None can happen here because the code does not compile.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.