请问c语言中,%c %d %f %lf分别是什么意思哦 c语言中%c,%d,%f分别是什么意思

C\u8bed\u8a00\u91cc\u9762\uff0c%d %c %f \u5206\u522b\u662f\u4ec0\u4e48\u610f\u601d\uff1f\u600e\u4e48\u7528\uff1f

%d\u662f\u7528\u6765\u8f93\u51fa\u5341\u8fdb\u5236\u6574\u578b\u6570\u636e\u7684\u5b9e\u9645\u957f\u5ea6\u8f93\u51fa\uff1b
%c\u662f\u4ee5\u5b57\u7b26\u5f62\u5f0f\u8f93\u51fa\uff0c\u53ea\u8f93\u51fa\u4e00\u4e2a\u5b57\u7b26\uff1b
%f\u662f\u4ee5\u5c0f\u6570\u5f62\u5f0f\u8f93\u51fa\u5355\u3001\u53cc\u7cbe\u5ea6\u5ea6\u6570\uff0c\u9690\u542b\u8f93\u51fa6\u4f4d\u5c0f\u6570\u3002
\u4f8b\u5b50\uff1a
int a=123;
CString temp;
// %d\u662f\u5341\u8fdb\u5236\u6574\u6570(int)
temp.Format(\u201c\u8f93\u51fa\uff1a%d\u201d,a);
::MessageBox(NULL,temp,"\u4fe1\u606f",0);
\u4fe1\u606f\u6846\u4f1a\u663e\u793a123
%d\u662f\u663e\u793a10\u8fdb\u5236\u7684\u6574\u6570\uff0c%c\u662f\u663e\u793a\u5355\u4e2a\u5b57\u7b26\uff0c%f\u662f\u663e\u793a\u6d6e\u70b9\u6570\uff08\u53ef\u7b80\u5355\u7684\u8ba4\u4e3a\u662f\u5c0f\u6570\u7684\u4e00\u79cd\uff09 printf("%d %c %f", 5, 'A' , 2.5 )
\u62d3\u5c55\u8d44\u6599\u8fd9\u4e9b\u662f\u683c\u5f0f\u58f0\u660e\uff0c\u683c\u5f0f\u58f0\u660e\u7531\u201c%\u201d\u548c\u683c\u5f0f\u5b57\u7b26\u7ec4\u6210\u3002
\u5e38\u7528\u7684\u683c\u5f0f\u5b57\u7b26\u6709\uff1a
1\uff09d\u683c\u5f0f\u7b26\uff0c\u7528\u6765\u8f93\u51fa\u4e00\u4e2a\u6709\u7b26\u53f7\u7684\u5341\u8fdb\u5236\u6574\u6570\uff1b
2\uff09c\u683c\u5f0f\u7b26\uff0c\u7528\u6765\u8f93\u51fa\u4e00\u4e2a\u5b57\u7b26\uff1b
3\uff09s\u683c\u5f0f\u7b26\uff0c\u7528\u6765\u8f93\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1b
4\uff09f\u683c\u5f0f\u7b26\uff0c\u7528\u6765\u8f93\u51fa\u5b9e\u6570\uff1b
5\uff09e\u683c\u5f0f\u7b26\uff0c\u7528\u683c\u5f0f\u58f0\u660e%e\u6307\u5b9a\u4ee5\u6307\u6570\u5f62\u5f0f\u8f93\u51fa\u5b9e\u6570\uff1b
6\uff09i\u683c\u5f0f\u7b26\uff0c\u4f5c\u7528\u8ddfd\u683c\u5f0f\u7b26\u4e00\u6837\uff0c\u4e0d\u8fc7\u4e60\u60ef\u7528%d\u800c\u5c11\u7528%i\uff1b
7\uff09o\u683c\u5f0f\u7b26\uff0c\u4ee5\u516b\u8fdb\u5236\u6574\u6570\u5f62\u5f0f\u8f93\u51fa\uff1b
8\uff09x\u683c\u5f0f\u7b26\uff0c\u4ee5\u5341\u516d\u8fdb\u5236\u6570\u5f62\u5f0f\u8f93\u51fa\u6574\u6570\u3002

C\u8bed\u8a00\u5e76\u6ca1\u6709\u5b9a\u4e49\u8fd9\u4e9b\u4e1c\u897f\uff0c\u662f\u67d0\u4e9b\u51fd\u6570\u5b9a\u4e49\u4e86\u8fd9\u4e9b\u4e1c\u897f\uff0c\u6bd4\u5982scanf()\u548cprintf()\uff0c\u8fd9\u4e9b\u4e1c\u897f\u662f\u201c\u63a7\u5236\u5b57\u7b26\u201d\uff0c\u4e5f\u5c31\u662f\u7528\u4e8e\u201c\u63a7\u5236\u8f93\u5165\u3001\u8f93\u51fa\u7684\u65b9\u5f0f\u201d\u7684\u5b57\u7b26\u3002
\u4ece\u8f93\u5165\u7684\u89d2\u5ea6\u6765\u8bf4\uff1a
\u5f53\u6211\u4eec\u4ece\u952e\u76d8\u8f93\u5165\u6570\u636e\u65f6\uff0c\u6211\u4eec\u6309\u4e0b\u7684\u952e\u5176\u5b9e\u90fd\u662f\u201c\u5b57\u7b26\u201d\uff0c\u4f46\u8fd9\u4e9b\u6309\u4e0b\u7684\u201c\u5b57\u7b26\u201d\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u89e3\u8bfb\u65b9\u5f0f\uff0c\u6bd4\u5982\u6211\u6309\u4e0b'3'\uff0c\u5b83\u53ef\u4ee5\u88ab\u8bfb\u53d6\u3001\u88ab\u8ba4\u4e3a\u662f\u6570\u5b573\uff0c\u4e5f\u53ef\u4ee5\u88ab\u8bfb\u53d6\u3001\u88ab\u8ba4\u4e3a\u662f\u5b57\u7b26'3'\uff0c\u6240\u4ee5\u6211\u4eec\u83b7\u53d6\u8f93\u5165\u7684\u65f6\u5019\u5c31\u8981\u201c\u6307\u5b9a\u8bfb\u53d6\u7684\u65b9\u5f0f\u201d\uff0c\u800c\u6307\u5b9a\u7684\u65b9\u6cd5\u5c31\u662f\u8bbe\u5b9a\u201c\u63a7\u5236\u5b57\u7b26\u201d\uff0c\u6bd4\u5982scanf()\u51fd\u6570\uff0c\u5982\u679c\u6211\u4eec\u4ee4\u5176\u4e3ascanf("%c",&char\u53d8\u91cf)\uff0c\u90a3\u4e48\u5f53\u6211\u4eec\u952e\u76d8\u6309\u4e0b\u201c123.12\u201d\u65f6\uff0cscanf()\u5c31\u4f1a\u83b7\u53d6\u7b2c\u4e00\u4e2a\u5b57\u7b26'1'\uff0c\u7136\u540e\u5b58\u8fdb\u90a3\u4e2achar\u53d8\u91cf\u4e2d\uff0c\u800c\u5982\u679c\u6211\u4eec\u4ee4\u5176\u4e3ascanf("%f",&float\u53d8\u91cf)\uff0c\u90a3\u4e48\u540c\u6837\u952e\u76d8\u6309\u4e0b\u201c123.12\u201d\u65f6\uff0cscanf()\u5c31\u4f1a\u5c06\u5b83\u4eec\u5f53\u4f5c\u4e00\u4e2a\u6574\u4f53\u3001\u4e00\u4e2a\u6d6e\u70b9\u6570123.12\uff0c\u7136\u540e\u5b58\u8fdb\u90a3\u4e2afloat\u578b\u53d8\u91cf\u91cc\u3002
\u800c\u4ece\u8f93\u51fa\u7684\u89d2\u5ea6\u6765\u8bf4\uff1a
\u5982\u679c\u6211\u4eecprintf("%c",int\u53d8\u91cf)\uff0c\u800c\u4e14\u8fd9\u4e2aint\u53d8\u91cf\u4e3a78\uff0c\u90a3\u4e48\u5c4f\u5e55\u4e0a\u8f93\u51fa\u7684\u5c31\u4e0d\u4f1a\u662f78\uff0c\u800c\u662f\u5b57\u7b26'N'\uff0c\u53ea\u6709printf("%d",int\u53d8\u91cf)\u65f6\uff0c\u5c4f\u5e55\u4e0a\u8f93\u51fa\u7684\u624d\u4f1a\u662f78\uff0c\u800cprintf()\u6709\u8fd9\u79cd\u673a\u5236\u7684\u539f\u56e0\uff0c\u5c31\u662fchar\u578b\u53d8\u91cf\u5176\u5b58\u50a8\u7684\u5176\u5b9e\u4e5f\u662f\u201c\u4e00\u4e2a\u6570\u5b57\u201d\uff0c\u5982\u679c\u4e0d\u6307\u660e\u8f93\u51fa\u7684\u65b9\u5f0f\uff0c\u90a3\u4e48\u5c31\u4e0d\u77e5\u9053\u8be5\u5982\u4f55\u89e3\u91ca\u53d8\u91cf\u4e2d\u7684\u6570\u5b57\u3002\u5f53\u7136\u8fd8\u6709\u5bf9\u4e8e\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u4e0d\u901a\u8fc7%s\u6765\u6307\u660e\u5176\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u90a3printf()\u5982\u4f55\u5224\u65ad\u8be5\u8f93\u51fa\u4e00\u4e2a\u5b57\u7b26\uff0c\u8fd8\u662f\u76f4\u5230'\0'\u7684\u6240\u6709\u5b57\u7b26\u5462\uff1f
\u81f3\u4e8e\u9898\u76ee\u4e2d\u6240\u8bf4\u7684%c,%d,%f\u5c31\u5206\u522b\u5bf9\u5e94\u7740\u201c\u5c06\u83b7\u53d6\u3001\u89e3\u91ca\u7684\u65b9\u5f0f\u8bbe\u4e3a\u4e00\u4e2a\u5b57\u7b26\u201d\uff0c\u201c\u5c06\u83b7\u53d6\u3001\u89e3\u91ca\u7684\u65b9\u5f0f\u8bbe\u4e3a\u4e00\u4e2aint\u578b\u53d8\u91cf\u201d\uff0c\u201c\u5c06\u83b7\u53d6\u3001\u89e3\u91ca\u7684\u65b9\u5f0f\u8bbe\u4e3a\u4e00\u4e2afloat\u578b\u201d

%c:是存取或者输出一个字符
%d:是存取或者输出一个整数
%lf: 是存取或者输出一个长整型小数。

都是转换符,%c要求将结果转换为字符型; %d 要求转换为十进制型;%f 转换为浮点型;%lf转换为长浮点型。

这都是格式控制符,%c是格式化输出字符型变量,%d格式化输出整型变量,%lf和%f分别是格式化输入和输出浮点型变量

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网