關於C 語言的字符串常量拼接


問題記錄:

C語言中,字符串是否可以通過連續的常量創建直接編輯拼接在一起?

比如下述語句賦值:

const char *path = “this is string one”   “this is string two”;

 //賦值后 *p 指向的字符串等於兩個語句拼接后的結果:

*p == “this is string onethis is string two”;

驗證:

 1 #include <stdio.h>
 2 
 3 #define AVAGO_FIRMWARE_PATH "/avago/firmware/"
 4 
 5 int main(void)
 6 {
 7     // int phy_id = 0;
 8     // int serdes_mode_line_1 = 0;
 9 
10     const char *path;
11     const char *fw_rev;
12     fw_rev = "0";
13     path = AVAGO_FIRMWARE_PATH "sbus_master/%s/sbus_master.%s_%s.rom" "\n";
14     printf(path,fw_rev,fw_rev,fw_rev);
15 
16     return 0;
17 }

 

 


 

程序運行后結果如下圖所示:

三段字符串產量未加任何連接符號,連續存儲並將字符串常量地址賦值給了指針path。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM