+1 vote
57 views

Is $>>=$ a single tocken or 2 tockens?

| 57 views
0

## 1 Answer

0 votes
Best answer

Both += and >>= are single operators - they fall under the category of compound assignment operators - https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Compound_assignment_operators - clearly says they are included in both C and C++, so there should be no debate.

For this reason, I will say there are single token.

by (1.9k points)
selected by
0

My life in short-->

1. Birth

2. Tagging @shashin on doubts

3. Death

0
Val+=5;

Will create syntax error right?
(As Val gets replaced by 10 bcz of macro)
+1
Yes. It will complain that it cannot assign to a literal, or that it needs an expression with a memory address.
0

@shashin

Is #define part count as token?

I mean macro or stdio part

0
afaik, #define, #include and '\' doesn't. typedef does.
0
Correct. For more details - please read up on preprocessor directives and in which stage of compilation they are evaluated. Typedef, iirc , is considered a synonym for a type and is evaluated during syntax analysis (I might be wrong on this) - but its counted towards a token.
0

One thing that bothers me, should we really ignore #defines tho?

e.g.

#define if if(rand() % 256)if

int main(){
int a = 4;
if(a == 4){
"";
}else{
printf("tf");
}
}

tokens here?!!

0
Not sure - try out on jdoodle.com and see how it evaluates. My understanding is that regardless of what's in the #define, the preprocessor just replaces it in the code before handing it to the compiler proper. Remember that compilers have a lot of different flavors, and aren't necessarily smart enough to properly interpret preprocessor directives.

I haven't dug that deep into the working of the C compiler tbh :)