{"id":288,"date":"2023-02-22T02:17:43","date_gmt":"2023-02-22T10:17:43","guid":{"rendered":"http:\/\/bitas.net.cn\/?page_id=288"},"modified":"2023-02-22T02:17:51","modified_gmt":"2023-02-22T10:17:51","slug":"099-2","status":"publish","type":"page","link":"http:\/\/bitas.net.cn\/index.php\/sourcecode\/099-2\/","title":{"rendered":"099 \u6307\u9488\u6570\u7ec4"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;string.h>\n\nstatic char words&#91;5]&#91;32] = { \n    \"Let\", \"us\", \"learn\", \"c\", \"language\"\n};\n\nint set_word(char **pstr)\n{\n    static int wi = 0;\n    if (NULL == (*pstr = malloc(strlen(words&#91;wi]))))\n        return -1; \n    strcpy(*pstr, words&#91;wi++]);\n    return 0;\n}\n\n#define ARR_SIZE 5\nint main(int argc, char *argv&#91;])\n{\n    char *ptrarr&#91;ARR_SIZE];\n    \/\/ set words to pointer array\n    for (int i = 0; i &lt; ARR_SIZE; i++)\n        set_word(&amp;ptrarr&#91;i]);\n    \/\/ print words\n    for (int i = 0; i &lt; ARR_SIZE; i++)\n        printf(\"%s \", ptrarr&#91;i]);\n    printf(\"\\b.\\n\");\n    \/\/ compare size\n    printf(\"size of words&#91;5]&#91;32]: %ld\\n\", \n        sizeof(words));\n    size_t ptrarr_size = 0;\n    ptrarr_size += sizeof(ptrarr);\n    for (int i = 0; i &lt; ARR_SIZE; i++)\n        ptrarr_size += strlen(ptrarr&#91;i]);\n    printf(\"size of pointer array: %ld\\n\",\n        ptrarr_size);\n    \/\/ free memory\n    for (int i = 0; i &lt; ARR_SIZE; i++)\n        free(ptrarr&#91;i]);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":127,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-288","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/comments?post=288"}],"version-history":[{"count":1,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/288\/revisions"}],"predecessor-version":[{"id":289,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/288\/revisions\/289"}],"up":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/127"}],"wp:attachment":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/media?parent=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}