Can you give examples of syntax errors?

QuestionsQuestions8 SkillsProYour First Linux LabSep, 09 2025
0167

Certainly! Here are some common examples of syntax errors in programming:

  1. Missing Semicolon (C++, Java, JavaScript):

    int main() {
        std::cout << "Hello, World!" // Missing semicolon here
        return 0;
    }
  2. Unmatched Parentheses (Python, Java, C++):

    print("Hello, World!"  # Missing closing parenthesis
  3. Incorrect Indentation (Python):

    def my_function():
    print("Hello, World!")  # Incorrect indentation
  4. Mismatched Quotes (Python, JavaScript):

    let message = "Hello, World!';  // Mismatched quotes
  5. Invalid Variable Name (Python, Java):

    int 1stNumber = 5;  // Variable names cannot start with a digit
  6. Missing Braces (C++, Java):

    if (x > 0)
        std::cout << "Positive";  // Missing braces for the if statement
  7. Using Reserved Keywords (Python, Java):

    def = 5  # 'def' is a reserved keyword and cannot be used as a variable name
  8. Incorrect Function Call (C++, Java):

    std::cout("Hello, World!");  // Missing '<<' operator

These syntax errors will typically result in compilation or runtime errors, depending on the programming language being used. Correcting these errors is essential for successful code execution.

0 Comments

no data
Be the first to share your comment!