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 parenthesis -
Incorrect Indentation (Python):
def my_function(): print("Hello, World!") # Incorrect indentation -
Mismatched Quotes (Python, JavaScript):
let message = "Hello, World!'; // Mismatched quotes -
Invalid Variable Name (Python, Java):
int 1stNumber = 5; // Variable names cannot start with a digit -
Missing Braces (C++, Java):
if (x > 0) std::cout << "Positive"; // Missing braces for the if statement -
Using Reserved Keywords (Python, Java):
def = 5 # 'def' is a reserved keyword and cannot be used as a variable name -
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.
