In C, what does a variable declaration with two asterisks (**) mean?

后端 未结 5 1816
我在风中等你
我在风中等你 2020-12-12 20:57

I am working with C and I\'m a bit rusty. I am aware that * has three uses:

  1. Declaring a pointer.
  2. Dereferencing a pointer.
  3. Multi
5条回答
  •  独厮守ぢ
    2020-12-12 21:29

    C and C++ allows the use of pointers that point to pointers (say that five times fast). Take a look at the following code:

    char a;
    char *b;
    char **c;
    
    a = 'Z';
    b = &a; // read as "address of a"
    c = &b; // read as "address of b"
    

    The variable a holds a character. The variable b points to a location in memory that contains a character. The variable c points to a location in memory that contains a pointer that points to a location in memory that contains a character.

    Suppose that the variable a stores its data at address 1000 (BEWARE: example memory locations are totally made up). Suppose that the variable b stores its data at address 2000, and that the variable c stores its data at address 3000. Given all of this, we have the following memory layout:

    MEMORY LOCATION 1000 (variable a): 'Z'
    MEMORY LOCATION 2000 (variable b): 1000 <--- points to memory location 1000
    MEMORY LOCATION 3000 (variable c): 2000 <--- points to memory location 2000
    

提交回复
热议问题