HERE IS THE CODE
int i = 3
int a=(i*+3);
NOT UNDERSTAND CODE IS
a=(i*+3)
value of a = 9
HERE IS THE CODE
int i = 3
int a=(i*+3);
NOT UNDERSTAND CODE IS
a=(i*+3)
value of a = 9
It is just a bad code formatting. To make the declaration clear rewrite it like
int i = 3;
int a = i * +3;
inserting blanks between tokens. Though the unary plus operator is redundant here.
One more confusing expression
int a = i+++3;
It is the same as
int a = i++ + 3;
From the C Standard (6.4 Lexical elements)
4 If the input stream has been parsed into preprocessing tokens up to a given character, the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token.
You can get many such confusing expressions omitting blanks between tokens.
Though in C there are dark corners that you should know.
For example if you have a function declaration like
void f( int x );
then it can be called like
(**********f)( 10 );
that is equivalent to
f( 10 );
Here is a demonstrative program
#include <stdio.h>
void f( int x )
{
printf( "I'm called with %d stars!\n", x );
}
int main(void)
{
( **********f )( 10 );
return 0;
}
Its output is
I'm called with 10 stars!
Context of usage in C
is needed to understand several multi-use symbols, such as the +
symbol, which by itself has at least 3 uses found commonly in C
expressions:
int a = 3 + 5;
)int a = +3 - (+3);
)for(int a=0; a<limit; a++)
) When used with other multi-use symbols, such as *
, determining whether it is sign, operator or incrementor is by context of usage.
Typically in this context you would use an implicit +
sign:
int a=(i*3);// i * +3
But it is also legal (but not as readable) to use an explicit sign. So by context of usage in this statement...
int a=(i*+3);// by context '+' is a sign in this case, not an operator
...is simply using an explicit sign for 3
, and the two statements are equivalent.
A more readable version:
int a=(i * (+3));
Another similar seemingly confusing scenario, but contextually meaningful:
int func(int *value){
int a = 10+*value;//by context '*' is de-referencing 'value' not multiplying
return a;
}
Note: readability could have been improved here by spacing:
int a = 10 + *value; //spacing is good for readability and removing ambiguity