c 語言 function

  • structure

     define example
    struct point
    {
    int x;
    int y;
    } ;

    int main(){
     struct point p;
    p.x=10;
    p.y=5;
    draw(p);
    •  進階定義的方法使用typeodef

    typedef:能夠自己定義資料型態的名稱,用在struct上能夠再定義struct型態的變數時不用再打一次struct。

     define example
    typedef struct {
    int x;
    int y;
    } point;

    int main(){
     point p;
    p.x=10;
    p.y=5;
    draw(p);

     
  • 輸入struct變數進入function內做運算

    void move(point *p){
     (*p).x++;
     (*p).y++;

    }

    
    
    或是
     

    void move(point *p){
     p->x++;
     p->y++;

    }
     

留言

這個網誌中的熱門文章

freeRTOS Deleting a Task

05 Software Timer Management

Interrupt Management