Recently I was trying to use the following code:
int number = 4;
number += other_variable;//2
...
printf("Number:%d\n",number);//-->6
but I had an error typing and instead I've got this code:
int number = 4;
number =+ other_variable;//2
...
printf("Number:%d\n",number);//-->2
Apparently this compiled with gcc 4.7.3
and gcc 4.4.3
and the result was as a normal assignment operator. The question is: Shouldn't be this a syntax error?
A syntax error occurs when a programmer writes an incorrect line of code. Most syntax errors involve missing punctuation or a misspelled name. If there is a syntax error in a compiled or interpreted programming language, then the code won't work.
Some of the most common causes of syntax errors in Python are: Misspelled reserved keywords. Missing quotes. Missing required spaces.
Syntax errors are mistakes in the use of the Python language, and are analogous to spelling or grammar mistakes in a language like English: for example, the sentence Would you some tea? does not make sense – it is missing a verb. Common Python syntax errors include: leaving out a keyword.
No - this is being parsed as:
number = +other_variable;
i.e. you have assignment and a unary + operator. You're reading it as =+
but it's two separate operators, =
and +
.
No, it's just a null op.
number = +other_variable;
number = 0 + other_variable;
As a complement to these operations, which negate:
number =- other_variable;
number = -other_variable;
number = 0 - other_variable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With