- เครื่องหมาย -> เรียกว่า indirect membership operator . ใช้ในการเข้าถึงข้อมูลผ่านพอร์ยเตอร์ นั้นคือ ทางซ้ายมือจะเป็นพอร์ยเตอร์ ทางขวามือจะเป็นชื่อของเมมเบอร์
- ตัวอย่าง ken.friend -> name; เมื่อ friend คือพอร์ยเตอร์ และ name คือ เมมเบอร์ของ structure นั้นๆ
- -> บางทีก็เรียกว่า structure pointer operator.
- อย่าลืมตั้งค่าให้พอร์ยเตอร์ก่อนใช้งาน
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef struct person | |
{ | |
char *name; | |
struct person *friend; | |
}Person; | |
int main(void) | |
{ | |
Person ted= {"Ted"}, susan= {"Susan"}, ken= {"Ken"}; | |
ken.friend = &susan; | |
ted.friend = &ken; | |
susan.friend = NULL; | |
printf("My name is %s , frined of mine is %s : ",ken.name,ken.friend -> name ); | |
return 0; | |
} |