如題,我在UBUNTU系統下利用記事本編寫了一段C程序,程序如下:main()
{ char h="Hello World!"; printf("%c\n",h);
}利用終端查看,命令如下:gcc -g -Wall hello.c -o hello.c結果出現這樣的錯誤:hello.c:1:1: 警告: 返回類型默認為‘int’ [-Wreturn-type]hello.c: 在函數‘main’中:hello.c:3:9: 警告: 初始化將指針賦給整數,未作類型轉換 [默認啟用]hello.c:4:2: 警告: 隱式聲明函數‘printf’ [-Wimplicit-function-declaration]hello.c:4:2: 警告: 隱式聲明與內建函數‘printf’不兼容 [默認啟用]hello.c:5:1: 警告: 在有返回值的函數中,控制流程到達函數尾 [-Wreturn-type]
2 回答

慕尼黑8549860
TA貢獻1818條經驗 獲得超11個贊
#include <stdio.h>int main(int argc,char *argv[]){ char str[] = "hello world"; printf("%s\n",str); return 0; }
提示隱式聲明是因為沒有包含頭文件:stdio.h
你的 printf
參數用的是 %c
(字符),而你想要打印的是字符串應該用 %s
。偏要打印 %c
,可以用 printf("%c",str[0]);
main
函數里沒有定義返回值,默認為 nt
, 而在程序結尾沒有返回值,所以提示
警告: 在有返回值的函數中,控制流程到達函數尾 [-Wreturn-type]

BIG陽
TA貢獻1859條經驗 獲得超6個贊
#include<stdio.h>int main(){ const char *h="Hello World!"; printf("%s\n",h); return 0; }
- 2 回答
- 0 關注
- 332 瀏覽
添加回答
舉報
0/150
提交
取消