Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 422 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is &&& operation in C

#1
#include <stdio.h>

volatile int i;

int main()
{
int c;

for (i = 0; i < 3; i++)
{
c = i &&& i;
printf("%d\n", c);
}

return 0;
}

The output of the above program compiled using `gcc` is

0
1
1

With the `-Wall` or `-Waddress` option, `gcc` issues a warning:

warning: the address of ‘i’ will always evaluate as ‘true’ [-Waddress]

How is `c` being evaluated in the above program?
Reply

#2
It's `c = i && (&i);`, with the second part being redundant, since `&i` will never evaluate to `false`.

For a user-defined type, where you can actually overload unary `operator &`, it might be different, but it's still a **very bad idea**.

If you **turn on warnings**, you'll get something like:

> warning: the address of ‘i’ will always evaluate as ‘true’
Reply

#3
There is no `&&&` operator or token in C. But the `&&` (logical "and") and `&` (unary address-of or bitwise "and") operators do exist.

By the [maximal munch](

[To see links please register here]

) rule, this:

c = i &&& i;

is equivalent to this:

c = i && & i;

It sets `c` to 1 if both `i` and `&i` are true, and to 0 if either of them is false.

For an int, any non-zero value is true. For a pointer, any non-null value is true (and the address of an object is always non-null). So:

It sets `c` to 1 if `i` is non-zero, or to `0` if `i` is equal to zero.

Which implies that the `&&&` is being used here just for deliberate obfuscation. The assignment might as well be any of the following:

c = i && 1;
c = !!i;
c = (bool)i; // C++ or C with <stdbool.h>
c = i ? 1 : 0; /* C */
c = i ? true : false; // C++
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through