第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

格式化IO函數(shù)中的轉(zhuǎn)換說明符%i和%d之間有什么區(qū)別(* printf / * scanf)

格式化IO函數(shù)中的轉(zhuǎn)換說明符%i和%d之間有什么區(qū)別(* printf / * scanf)

C++ C
拉風(fēng)的咖菲貓 2019-08-26 14:10:01
格式化IO函數(shù)中的轉(zhuǎn)換說明符%i和%d之間有什么區(qū)別(* printf / * scanf)%d和%i用作格式說明符的區(qū)別是什么printf?
查看完整描述

3 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

當(dāng)用于輸出時(shí)它們是相同的,例如printf

但是,當(dāng)用作輸入說明符時(shí),這些是不同的,例如scanf,其中,%d將整數(shù)掃描為帶符號(hào)的十進(jìn)制數(shù),但%i默認(rèn)為十進(jìn)制,但也允許十六進(jìn)制(如果前面帶有0x)和八進(jìn)制(如果前面帶有0)。

所以03327 %i歲,但33歲%d。


查看完整回答
反對(duì) 回復(fù) 2019-08-26
?
侃侃無極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

%i%d格式說明符之間沒有區(qū)別printf。我們可以通過參考草案C99標(biāo)準(zhǔn)部分來看到這一點(diǎn)7.19.6.1 .fprintf函數(shù)也涉及printf格式說明符,它在第8段中說:

轉(zhuǎn)換說明符及其含義是:

并包括以下項(xiàng)目:

d,i     The int argument is converted to signed decimal in the style        [?]dddd. The precision specifies the minimum number of digits to
        appear; if the value being converted can be represented in fewer
        digits, it is expanded with leading zeros. The default precision is
        1. The result of converting a zero value with a precision of zero is
        no characters.

另一方面,由于scanf存在差異,%d假設(shè)基數(shù)為10而%i自動(dòng)檢測(cè)基數(shù)。我們可以通過將部分看到這個(gè)7.19.6.2 fscanf函數(shù)覆蓋scanf相對(duì)于格式說明,在第12這樣說的:

轉(zhuǎn)換說明符及其含義是:

并包括以下內(nèi)容:

d     Matches an optionally signed decimal integer, whose format is the
      same as expected for the subject sequence of the strtol function with
      the value 10 for the base argument. The corresponding argument shall
      be a pointer to signed integer.i     Matches an optionally signed integer, whose format is the same as
      expected for the subject sequence of the strtol function with the
      value 0 for the base argument. The corresponding argument shall be a
      pointer to signed integer.


查看完整回答
反對(duì) 回復(fù) 2019-08-26
?
忽然笑

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊

在我看來,在sscanf中可能出現(xiàn)零填充的int似乎是最合理的默認(rèn)行為。如果你不期待Octal,那可能會(huì)導(dǎo)致微妙的錯(cuò)誤。所以這表明%d是一個(gè)很好的說明符,當(dāng)你必須任意選擇一個(gè)時(shí),除非你明確想要讀取八進(jìn)制和/或十六進(jìn)制。

查看完整回答
反對(duì) 回復(fù) 2019-08-26
  • 3 回答
  • 0 關(guān)注
  • 1127 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)