Bitwise operator

Guys, please, can anyone explain to me how the following code works, if you please?
int n;
char b, l;
char s[100];
cin >> n;
for(int i = 0; i < strlen(s); i++)
" b |= s[i] <= s[i + n]; " ___> I'M INTERESYED ON THIS CODE PERFORMANCE!
" l |= s[i] >= s[i + n]; " --->

what will that two-code lines (above) performs.
Thanks beforehand!

I'm interested in this:
cin >> n;

What value of n is supposed to be input, and why?

Notice this code: s[i + n]; It is accessing an individual character of the string s at position i + n. Unless the values of both i and n are carefully controlled, the result may be an offset which is outside the boundaries of the string, thus giving an error.

Now this: s[i] <= s[i + n]
The result of this expression is either true or false (1 or 0). It is comparing two characters (which we hope might be within the string). If n was equal to 1, it would compare consecutive characters and might be used to check for ascending/descending sequence.

Finally the result is used to set "on" the value stored in variable b. b should be initialised to zero, or the result is unpredictable.
At the end of the loop, b will be zero only if every test gave a false result.

Overall, this is a buggy and incomplete fragment of code which would need some work before it could be useful.
Last edited on
Topic archived. No new replies allowed.