zoukankan      html  css  js  c++  java
  • 关于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" "
    ";
    14     printf(path,fw_rev,fw_rev,fw_rev);
    15 
    16     return 0;
    17 }

    程序运行后结果如下图所示:

    三段字符串产量未加任何连接符号,连续存储并将字符串常量地址赋值给了指针path。

  • 相关阅读:
    python爬虫(二)_HTTP的请求和响应
    python迭代器
    矩阵快速幂
    hdu 2256 Problem of Precision
    牛客练习赛17 ABD
    hdu 1575 Tr A
    hdu 1757 矩阵快速幂
    51nod 1402最大值
    51nod 1393 0和1相等串
    勤奋的杨老师
  • 原文地址:https://www.cnblogs.com/yochingbox/p/12051534.html
Copyright © 2011-2022 走看看