<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # memset ~~~ #include <string.h> void * memset(void *s, int c, size_t n); ~~~ 功能:將s的內存區域的前n個字節以參數c填入 參數 * s: 需要操作內存s的首地址 * c: 填充字符,c雖然參數為int,但必須是unsigned char,范圍為0-255 * n: 指定需要設置的大小 返回值: s的首地址 ~~~ int main() { //創建堆空間 int * p = (int *)malloc(sizeof(int) * 10); //初始化 //參數: 目標 值 字節大小 memset(p, 0, 40); for (int i = 0; i < 10; ++i) { printf("%d\n", p[i]); } free(p); getchar(); return EXIT_SUCCESS; } ~~~ 輸出全是0 如果是1的話 ~~~ int main() { //創建堆空間 int * p = (int *)malloc(sizeof(int) * 10); //初始化 //參數: 目標 值 字節大小 memset(p, 1, 40); for (int i = 0; i < 10; ++i) { printf("%d\n", p[i]); } free(p); getchar(); return EXIT_SUCCESS; } ~~~ 輸出全是16843009 因為int是4個字節,內存16字節表示`00 00 00 00` 1的話是`01 01 01 01` 這個16進制轉為10進制就是16843009 # memcpy ~~~ #include <string.h> void * memcpy(void * dest, const void * src, size_t n) ~~~ 功能: 拷貝src所指的內存內容的前n個字節到dest所值的內存地址上 參數: * dest: 目的內存首地址 * src: 源內存首地址,注意: **dest和src所指的內存空間不可重疊** * n: 需要拷貝的字節數 返回值: dest的首地址 ~~~ int main() { int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; //創建堆空間 int * p = (int *)malloc(sizeof(int) * 10); memcpy(p, arr, 40); for (int i = 0; i < 10; ++i) { printf("%d\n", p[i]); } free(p); getchar(); return EXIT_SUCCESS; } ~~~ 數組內部的copy ~~~ int main() { int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; memcpy(&arr[2], arr, 20); for (int i = 0; i < 10; ++i) { printf("%d\n", arr[i]); } getchar(); return EXIT_SUCCESS; } ~~~ # memmove memmove()功能用法和memcpy()一樣,區別在于: dest和src所指的內存空間重疊時,memmove()仍然能處理,不過執行效率比memcpy低些 ~~~ int main() { int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; memmove(&arr[2], arr, 20); for (int i = 0; i < 10; ++i) { printf("%d\n", arr[i]); } getchar(); return EXIT_SUCCESS; } ~~~ # memcmp ~~~ #include <string.h> int memcmp(const void *s1, const void *s2, size_t n); ~~~ 功能: 比較s1和s2所指向內存區域的前n個字節 參數: * s1: 內存首地址1 * s2: 內存首地址2 * n: 需比較的前n個字節 返回值: * 相等=0 * 大于>0 * 小于<0 ~~~ int main() { int arr1[10] = {1, 2, 3, 4, 5, 6, 7, 8}; int arr2[5] = {1, 2, 3, 4, 5}; int val = memcmp(arr1, arr2, 20); if (!memcmp(arr1, arr2, 8)) { printf("前2個數組元素內容相同\n"); } printf("%d\n", val); getchar(); return EXIT_SUCCESS; } ~~~ # calloc 堆分配內存API ~~~ #include <stdlib.h> void *calloc(10, sizeof(int)); 功能: 在內存動態存儲區中分配nmemb塊長度為size字節的連續區域.calloc自動將分配的內存置0 參數: nmemb: 所需內存單元數量 size: 每個內存單元的大小(單位:字節) 返回值: 成功: 分配空間的起始地址 失敗: NULL ~~~ # realloc ~~~ #include <stdlib.h> void *realloc(void *ptr, size_t size); 功能: 重新分配用malloc或者calloc函數在堆中分配內存空間的大小 realloc不會自動清理增加的內存,需要手動清理,如果指定的地址后面有連續的空間,那么就會在已有地址基礎上增加內存,如果指定的地址后面沒有空間,那么realloc會重新分配新的連續內存,把舊內存的值拷貝到新內存,同時釋放舊內存 參數: ptr: 為之前用malloc或者calloc分配的內存地址,如果此參數等于NULL,那么和realloc與malloc功能一致 size: 為重新分配內存的大小,單位:字節 返回值: 成功: 新分配的堆內存地址 失敗: NULL ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看