double exclamation point

Hey!!

I am curently studying this code. I could not understand/find what the double exclamation point means! could anyone help me please?!
Has it anything to do with the use of pointer to pointer in the array?



int Corruptpack(unsigned char **pack, unsigned char *mean, unsigned num, unsigned size)
{
unsigned i, j, n;

if (num < 3) return 1;

for (i=0; i<size; i++) {
for (j=0; j<num; j++) mean[i] += !!pack[j][i];
mean[i] = mean[i] > num/2;
}

for (n=0, i=0; i<size; i++) n += mean[i];

return !!n;
}


Thanks in advance!
Last edited on
The ! operator is the logical-NOT operator.

In C/C++, integers can be implicitly cast to boolean values according to the rule that 0 is false and anything else is true. The boolean false has "value" 0 and true has "value" 1.

Programmers sometimes take advantage of the implicit boolean conversion to perform the conversion:

f(x) = { 0, iff x == 0, and 1 iff x != 0 }

So given an integer x, !!x is 1 iff x is not zero and 0 otherwise.
I got it :) Thank you very much jsmith!!!
Topic archived. No new replies allowed.