programming C problem

2006-12-07 5:57 pm
#include
main( )
{
printf("%u\\n%x\\n%X\\n%e\\n%E\\n%f\\n%g\\n%G\\n%c\\n%s\\n%4d\\n
%4d\\n%.3f\\n%.11s\\n%10s\\n%-10s\\n",
455,32000,2000000000,455,455,455,455,1234567.89,1234567.89,1234567.89,1234567.89.'a',"this is a string",1,12345,123.94536,"Happy Birthday","Hello","Hello");
}
更新1:

the output is: 455 1c7 1C7 1.234568e+06 1.234568E+06 1234567.890000 1.23457e+0.6 1.23457E+0.6 A This is a string 1 12345 123.945 Happy Birthday Hello Hello

更新2:

1)why must type after #include? 2)why must place a % before conversion specifier (eg: %d ) 3)can u explain the "%4d" the output is " 1 ", what is the meaning of 4? 4)why there is a . before c.s (eg: %.11s) 5)why there is a - before c.s (eg: %-10s)

更新3:

correction for the command #include main( ) { printf(“%u\n%x\n%X\n%e\n%E\n%f\n%g\n%G\n%c\n%s\n%4d\n %4d\n%.3f\n%.11s\n%10s\n%-10s\n”, 455,455,455,455,1234567.89,1234567.89,1234567.89,1234567.89, ‘A’, “This is a string”,1,12345,123.94536,“Happy Birthday”, “Hello” , “Hello”); }

回答 (1)

2006-12-11 7:12 pm
✔ 最佳答案
1)why must type after #include?
#include 係header file, 即係依個program 要用咩library 或者其他已起好既 header, 要放係第一行係因為當你要 compile 時, compiler 要嘗試link 返其他header define 左既 function, 如果唔係佢就check 唔到有冇其他地方知該function 有冇被起好

2)why must place a % before conversion specifier (eg: %d )
% 係 reserve word, 主要係比compiler 知道係要print out / read in 一個variable, 而d 係類吃

3)can u explain the "%4d" the output is " 1 ", what is the meaning of 4?
%4d 係只小要有4個位

4)why there is a . before c.s (eg: %.11s)
%.11s 最多 print 11個位

5)why there is a - before c.s (eg: %-10s)
%-10s 各左移10個位

條link 雖然係 C++, 但解釋一樣


收錄日期: 2021-04-21 00:49:59
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061207000051KK00727

檢視 Wayback Machine 備份