課程
/后端開發
/C
/C語言入門
為什么我的運行結果是99
2019-02-18
源自:C語言入門 2-8
正在回答
#include <stdio.h>
int main()
{
? ? char c = 'a';
? ? int n = c;? ? ? ? //將c賦值給n,記住不要給c添加引號
? ? float f = c;? ? ? //將c賦值給f
? ? double d = c;? ? ?//將c賦值給d
? ? printf("%d\n",n);
? ? printf("%f\n",f);
? ? printf("%lf\n",d);
? ? return 0;? ??
}
? ? int n = 'c';? 這種寫法是錯誤的,因為在ASCII中c的值就是99.這種寫法相當于將n f d賦值??
#include <stdio.h>int main(){??? double num = 2.5;????? //定義浮點型變量num并賦值為2.5??? printf("num的整數部分是%d\n",(int)num);? ??? return 0;}
舉報
C語言入門視頻教程,帶你進入編程世界的必修課-C語言
1 回答運行結果?
5 回答運行結果?
2 回答運行結果???
3 回答運行結果?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-02-19
#include <stdio.h>
int main()
{
? ? char c = 'a';
? ? int n = c;? ? ? ? //將c賦值給n,記住不要給c添加引號
? ? float f = c;? ? ? //將c賦值給f
? ? double d = c;? ? ?//將c賦值給d
? ? printf("%d\n",n);
? ? printf("%f\n",f);
? ? printf("%lf\n",d);
? ? return 0;? ??
}
? ? int n = 'c';? 這種寫法是錯誤的,因為在ASCII中c的值就是99.這種寫法相當于將n f d賦值??
2019-02-18
#include <stdio.h>
int main()
{
??? double num = 2.5;????? //定義浮點型變量num并賦值為2.5
??? printf("num的整數部分是%d\n",(int)num);?
??? return 0;
}