Logical shift with signed numbers
The C standard does not guarantee that an int is 32 bits.  Even though the problem guarantees that 0 ≤ n ≤ 31, your code fails if run on a machine with a 64-bit int.  One way to resolve that problem is to be explicit about the size of your inputs:

#include &lt;stdint.h&gt;

int32_t logicalShift(int32_t x, int n) {
    …
}




The C standard says (C99 §6.5.7):


  The result of E1 &gt;&gt; E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of \$\dfrac{\mathrm{E1}}{2 ^ \mathrm{E2}}\$. If E1 has a signed type and a negative value, the resulting value is implementation-defined.


Therefore, your best bet is to treat x as an unsigned type:

int logicalShift(int x, int n) {
    return (unsigned int)x &gt;&gt; n;
}