C語言中的小細節

來源:互聯網
上載者:User

1.位溢出

int和long現在都是4個位元組,不過現在的c裡面都沒給出一個越界溢出的api函數,得自己注意 a = 0xffffffff ,b = 0xffffffff 然後 a+b,或者a×b都會溢出,但是這樣的一處float和double都會遇到

在asm裡面會用jo和jno來判斷溢出標誌位

2.unsinged  int(long)和 singed int(long) a = 0xffffffff 右移位

while((a=a>>1)) printf("0x%x/n");

singed int(long)的時候就會死迴圈

這個是移位機制裡面的問題,反組譯碼可以看到一個是用的sha另一個是shr。

3.一個字串的反轉

who are you --> uwho are yo->ouwho are y->youwho are ->you who are ->you ewho ar->you rewho a->you arewho->you are who

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.