Certainly! Here are some common examples of syntax errors in programming:
Missing Semicolon (C++, Java, JavaScript):
int main() { std::cout << "Hello, World!" // Missing semicolon here return 0; }Unmatched Parentheses (Python, Java, C++):
print("Hello, World!" # Missing closing parenthesisIncorrect Indentation (Python):
def my_function(): print("Hello, World!") # Incorrect indentationMismatched Quotes (Python, JavaScript):
let message = "Hello, World!'; // Mismatched quotesInvalid Variable Name (Python, Java):
int 1stNumber = 5; // Variable names cannot start with a digitMissing Braces (C++, Java):
if (x > 0) std::cout << "Positive"; // Missing braces for the if statementUsing Reserved Keywords (Python, Java):
def = 5 # 'def' is a reserved keyword and cannot be used as a variable nameIncorrect 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.
