C陣列和指標

stitchCat發表於2024-08-22
// Online C compiler to run C program online
#include <stdio.h>

int main() {

    char arr[2] = {1, 2};
    
    char *parr0 = NULL;
    char *parr1 = NULL;
    
    char **pparr0 = NULL;
    char **pparr1 = NULL;
    
    printf("%p %p %p\n", arr, &arr[0], &arr);
    printf("%p %p %p\n", arr + 1, (&arr[0]) + 1, (&arr) + 1);
    
    parr0 = arr;
    parr1 = &arr[0];
    
    printf("%p %p %p %p\n", parr0, arr, parr1, &arr[0]);
    
    pparr0 = &parr0;
    pparr1 = &parr1;
    
    printf("%p %p %p %p\n", *pparr0, parr0, *pparr1, parr1);
    
    printf("%d %d\n", *pparr0[0], *pparr1[0]);
    printf("%d %d %d %d\n", **pparr0, **pparr1, *(*pparr0 + 1), *(*pparr1 + 1));
    printf("%p %p\n", pparr0[0], pparr1[0]);
    
    return 0;
}

相關文章