7
เหตุใดฉันไม่สามารถเข้าถึงตัวชี้ไปยังตัวชี้สำหรับสแต็กอาเรย์
โปรดดูรหัสต่อไปนี้ มันพยายามที่จะส่งผ่านอาร์เรย์เป็นchar**ฟังก์ชั่น: #include <stdio.h> #include <stdlib.h> static void printchar(char **x) { printf("Test: %c\n", (*x)[0]); } int main(int argc, char *argv[]) { char test[256]; char *test2 = malloc(256); test[0] = 'B'; test2[0] = 'A'; printchar(&test2); // works printchar((char **) &test); // crashes because *x in printchar() has an invalid pointer free(test2); …
35
c