关于scanf函数和printf函数的用法与区别(菜鸟级提问!!)

2020-09-22 财经 92阅读
scanf("%d",&num);
printf("%d",num);
因为scanf and printf是格式化输出,所以分两个部分,第一部分用分号扩起,%加格式,%d代表整数十进制,后面是相关数据,但scanf 将取得数据 放到num地址 所以加取地址符号&
而printf使用是 直接跟想输出的数的变量名字num
#include
void main( void )
{
int i, result;
float fp;
char c, s[81];
wchar_t wc, ws[81];
printf( "\n\nEnter an int, a float, two chars and two strings\n");
result = scanf( "%d %f %c %C %s %S", &i, &fp, &c, &wc, s, ws );
printf( "\nThe number of fields input is %d\n", result );
printf( "The contents are: %d %f %c %C %s %S\n", i, fp, c, wc, s, ws);
wprintf( L"\n\nEnter an int, a float, two chars and two strings\n");
result = wscanf( L"%d %f %hc %lc %S %ls", &i, &fp, &c, &wc, s, ws );
wprintf( L"\nThe number of fields input is %d\n", result );
wprintf( L"The contents are: %d %f %C %c %hs %s\n", i, fp, c, wc, s, ws);
}
输出
Enter an int, a float, two chars and two strings
71
98.6
h
z
Byte characters
The number of fields input is 6
The contents are: 71 98.599998 h z Byte characters
Enter an int, a float, two chars and two strings
36
92.3
y
n
Wide characters
The number of fields input is 6
The contents are: 456 92.300003 y n Wide characters
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com