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

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

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