开发者

C Output for Homework [closed]

开发者 https://www.devze.com 2023-02-03 22:34 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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