What does this statement yield?

F

Frank

I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.


phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}
 
A

Alf P. Steinbach

* Frank:
I am reading other people's code and come across this statement.
Does it mean phase revolve arround 0,1,2 and 3 & 3 makes 0?

Thank you.


phase = 0;
for (i = 0; i <= 100; i++) {
phase=(phase+1)&3;
}

For integer types '&3' is effectively the same as '%4'.

I.e. for such types the code should yield 101%4 = 1.

If 'phase' is of a user-defined type then nothing can be said.
 
F

Frank

Alf P. Steinbach said:
* Frank:

For integer types '&3' is effectively the same as '%4'.

I.e. for such types the code should yield 101%4 = 1.

If 'phase' is of a user-defined type then nothing can be said.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Thank you. Understood.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top