Why use double indirection? or Why use pointers to pointers?

前端 未结 18 2277
失恋的感觉
失恋的感觉 2020-11-22 10:37

When should a double indirection be used in C? Can anyone explain with a example?

What I know is that a double indirection is a pointer to a pointer. Why would I ne

18条回答
  •  一向
    一向 (楼主)
    2020-11-22 11:27

    Simple example that you probably have seen many times before

    int main(int argc, char **argv)
    

    In the second parameter you have it: pointer to pointer to char.

    Note that the pointer notation (char* c) and the array notation (char c[]) are interchangeable in function arguments. So you could also write char *argv[]. In other words char *argv[] and char **argv are interchangeable.

    What the above represents is in fact an array of character sequences (the command line arguments that are given to a program at startup).

    See also this answer for more details about the above function signature.

提交回复
热议问题