I am new to C and got a little confused. I have code where I am using += operator with a variable when declared but it is giving me an error for this operator, but working fine when used inversely i.e. =+. Please explain why?
Here is the code:
int i = 0;
int g = 99;
do
{
int f += i; //Here += is throwing error and =+ is working fine why?
printf("%-6s = %d ","This is",f);
i++;
} while(i<10);
Error as
ff.c:16:11: error: invalid '+=' at end of declaration; did you mean '='?
int f += i;
^~
=
1 error generated.
It's working this way:
int i = 0;
int g = 99;
do
{
int f =+ i; //Here += is `your text throwing error and =+ is working fine why?
printf("%-6s = %d ","This is",f);
i++;
} while(i<10);
+=is not the same as=+.=+and=-initially. However, when writing this asf=-ithey didn't know if it was meant to bef =- iorf = -i. So the assignment was changed to+=and-=(over 50 years ago).