<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # C 程序:在結構中動態存儲數據 > 原文: [https://www.programiz.com/c-programming/examples/structure-dynamic-memory-allocation](https://www.programiz.com/c-programming/examples/structure-dynamic-memory-allocation) #### 在此示例中,您將學習存儲用戶使用動態內存分配輸入的信息。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 指針](/c-programming/c-pointers) * [C 動態內存分配](/c-programming/c-dynamic-memory-allocation) * [C 結構](/c-programming/c-structures) * * * 該程序要求用戶存儲`noOfRecords`的值,并使用`malloc()`函數為`noOfRecords`結構變量動態分配內存。 * * * ## 演示結構的動態內存分配 ```c #include <stdio.h> #include <stdlib.h> struct course { int marks; char subject[30]; }; int main() { struct course *ptr; int i, noOfRecords; printf("Enter the number of records: "); scanf("%d", &noOfRecords); // Memory allocation for noOfRecords structures ptr = (struct course *)malloc(noOfRecords * sizeof(struct course)); for (i = 0; i < noOfRecords; ++i) { printf("Enter the name of the subject and marks respectively:\n"); scanf("%s %d", &(ptr + i)->subject, &(ptr + i)->marks); } printf("Displaying Information:\n"); for (i = 0; i < noOfRecords; ++i) printf("%s\t%d\n", (ptr + i)->subject, (ptr + i)->marks); return 0; } ``` **輸出** ```c Enter the number of records: 2 Enter the name of the subject and marks respectively: Programming 22 Enter the name of the subject and marks respectively: Structure 33 Displaying Information: Programming 22 Structure 33 ```
                  <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>

                              哎呀哎呀视频在线观看