מבנים ב-C
יש לי בעיה לתפוס את העקרונות של מבנים: זה לא ממש הבנתי איך typedef עוזר לי/מגביל אותי. מדוע נגיד זה חוקי:
יש לי בעיה לתפוס את העקרונות של מבנים: זה לא ממש הבנתי איך typedef עוזר לי/מגביל אותי. מדוע נגיד זה חוקי:
#include <stdio.h> struct coords { int x; int y; }point; int main() { struct coords top={16,25}; point.x=9; point.y=10; printf("%d %d\n", point.x, point.y); printf("%d %d\n", top.x, top.y); }
אבל אם אני עושה ככה זה לא חוקי:#include <stdio.h> typedef struct coords { int x; int y; }point; int main() { coords top={16,25}; point.x=9; point.y=10; printf("%d %d\n", point.x, point.y); printf("%d %d\n", top.x, top.y); }
מבחינת זה שאסור לי לכתוב יותר point.x point.y למשל...