zoukankan      html  css  js  c++  java
  • Algorithm for understanding pointer in C

    1. find the variable name
    2. translate the operator adjacent to the var name with prioirty
    3. translate anthor symbol adjacent to the var in the opposite direction
    4. go back to step 2
    5. finally, deal with the class declarition such as int and so forth
    // only a * on the left side adjacent to p, there is no symbol on the right side
    int *p // 1
    
    // * on the left side, [] on the right side. but [] is prior to *.
    // the order is p -> p[13] -> int *(p[13])
    int *p[13] // 2
    
    // this order is constrant by ()
    int *(p[13]) // 3
    
    // p -> *p -> int * *p
    int **p // 4 
    
    
    int (*p)[13] // 5
    
    // () is prior to *
    // f is a function which returns a pointer to int
    // f -> f() -> int *(f())
    int *f() // 6
    
    // f is a pointer for the priority of *
    // and then, the pointer point to function
    // f -> *f -> *f() -> int (*f())
    int (*f)() // 7
    
    // f is a function which returns a pointer.
    // the pointer point to a array of 13 elements.
    // each element is a pointer which point to a function which return int.
    int (*(*f())[13])() // 8
    
    // x is a array of which each is a pointer.
    // the pointer point to a function which return pointer
    // that point to a array of int
    int (*(*x[3])())[5] // 9
    

    other refs

  • 相关阅读:
    [CF997E] Good SubSegment
    CF916E
    BZOJ2006 超级钢琴
    BZOJ4571
    凸包总结
    树形DP入门
    bzoj4300 绝世好题(位运算+DP)
    bzoj4552 [Tjoi2016&Heoi2016]排序 (线段树+二分)
    SP1716 GSS3
    Noip2009 Hankson 的趣味题 (简单数学)
  • 原文地址:https://www.cnblogs.com/ijpq/p/15428297.html
Copyright © 2011-2022 走看看