开发者

C Output for Homework [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JS百科 Closed 12 years ago.
int main()
{
    signed int bit=512, mBit;
    {
        mBit = ~bit;
        bit = bit & ~bit ;
        printf("%d %d", bit, mBit);
    }
    return 0;
}

a. 0, 0

b. 0, 513

c. 512, 0

d. 0, -513

Guys I am not having the answer of this question and also not able to interpret the question.so could you please provide your answers with proper explanation.


The correct answer is d: http://ideone.com/frKOz

  • bit is 0 because bit & ~bit always results in a zero (1000000000 & 0111111111).
  • mbit is -513 because inverting 512 is -513.

Edit: Why is mbit -513?

See explanation of signed-integer-handling: http://www.rwc.uc.edu/koehler/comath/13.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜