第一個問題:在給char型變數賦值為255,但以%d型輸出時為什么會顯示-1,如下面的程式
int main()
{
char num_max=255;
printf("num_max=%d\n",num_max);
return 0;
}
編譯運行結果:num_max=-1
第二個問題:為什么以%s輸出時會多了一個字母
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[5]="apple";
printf("str:%s\n",str);
return 0;
}
編譯運行結果:apple F
uj5u.com熱心網友回復:
第一個printf("num_max=%u\n",num_max);
第二個
char str[6]="apple";
uj5u.com熱心網友回復:
第一個 資料溢位,變成-1第二個 字串陣列最后一位是 '\0'
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/108747.html
標籤:C語言
