當前位置:首頁 » 操作系統 » linuxc指針

linuxc指針

發布時間: 2023-06-18 19:59:08

linuxc語言關於指針和字元串函數調用的問題—段錯誤

printf("%s\n",p1);//p1代表的是字串首地址。
*p="goodbye";
//編譯時會出錯。正確格式p="goodbye";
char
*func()
//函數指針的寫法,返回一個指針,如庫函數malloc,返回就是一段內存塊的首地址。
你的程序是兩次輸出hello,如果要將指針內容更改,可以使用你說的這個格式char
*func()
#include
"stdio.h"
char
*func();
int
main()
{
char
*p1="hello";
printf("%s\n",p1);
/*
正確輸出
hello,*p1的首地址
*/
p1=func();
/*
獲得goodbye的首地址
*/
printf("%s\n",p1);
getch();
return
0;
}
char
*func()
{
char
*p;
return
p="goodbye";
/*將goodbye的首地址傳回*/
}

熱點內容
gradle命令編譯apk 發布:2025-03-22 01:02:02 瀏覽:305
我的世界玩壞伺服器 發布:2025-03-22 01:01:59 瀏覽:950
紅米note安卓80怎麼刷機 發布:2025-03-22 00:49:46 瀏覽:214
linux字體緩存 發布:2025-03-22 00:49:09 瀏覽:979
明銳pro為什麼比高爾夫配置還要高 發布:2025-03-22 00:24:43 瀏覽:131
賣房解壓擔保 發布:2025-03-22 00:18:57 瀏覽:452
java打開頁面 發布:2025-03-22 00:18:41 瀏覽:449
mt4ea源碼 發布:2025-03-21 23:59:08 瀏覽:533
文件夾加密隱藏 發布:2025-03-21 23:56:24 瀏覽:19
setjava用法 發布:2025-03-21 23:54:59 瀏覽:183