Arithmetic or logical right shifts Is this code correct? Is there any major improvement I can ad in terms of number of operations?

#include &lt;stdio.h&gt;

/* function that yields 1 when run on a machine that uses
arithmetic right shifts for int's and 0 otherwise */

/* use only &lt;&lt; &gt;&gt; ! &amp; ~ ^ and constants between 0x0 and 0xff*/

int int_what_shifts();

int main(){
    int_what_shifts();
}

int int_what_shifts(){

    int mask = (0x80 &lt;&lt; 24);

    printf("%d\n",!!(mask&gt;&gt;31));

    return !!(mask &gt;&gt; 31);
}
Replace 24 with (sizeof(int) - 1) * CHAR_BIT. Otherwise the code would fail on a non-32-bit integer machines. Also, using -1 as a probe makes you independent of the bitness of a system:

return ((-1) &gt;&gt; 1) == (-1);


PS: you don't want to print anything from such a specialized routine.