struct point {
int x;
int y;
};
main() {
struct point a;
a.x = 5;
a.y = 10;
printf("%d %d", a.x, a.y);
}
5 10
在這裏,如果我想動態添加INT相同的結構的構件(int z
)。 程序是什麼?
我曾嘗試:
struct point {
int x;
int y;
};
struct newpoint {
struct point a;
int z;
};
我已經嘗試了上述步驟,通過它,我們增加了一個新成員和老結構point
新結構newpoint
。但這不是我想要的,我想動態添加新成員相同的結構。我在面試中得到了這個問題。
你不能添加成員,但你可以創建一個結構數組,並改變數組的大小。 – ryyker
可能的重複:https://stackoverflow.com/questions/6187908/is-it-possible-to-dynamically-define- a-struct-in-c –