Pointer Pointer leads to Segmentation Fault in C

ChiefHan

Why can I create an array of pointers and dereference its (pointer-)elements.

int a = 1;
int* arr[1];

arr[0] = &a;

But cannot do the same with pointer to pointers:

int** arr2;
arr2[0] = &a;
--> Seg fault
JCWasmx86

int** arr2;

You don't initialize this pointer. Accessing it is undefined behavior and can/will result in crashes.

To initialize use something like int** arr2 = malloc(<someSize> * sizeof(*arr2)). (PS: malloc may return NULL, and you have to use free to return the memory).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C array pointer segmentation fault

From Dev

Pointer-to-a-pointer in C throws segmentation fault

From Dev

Segmentation Fault, pointer issue?

From Dev

Segmentation fault on pointer

From Dev

Segmentation fault, pointer issue

From Dev

segmentation fault when trying to deference pointer : C

From Dev

Odd C pointer segmentation fault errors

From Dev

Why this pointer got a Segmentation fault C?

From Dev

segmentation fault using char pointer (C)

From Dev

segmentation fault when trying to deference pointer : C

From Dev

Segmentation fault error with pointer array in C

From Dev

Pointer to pointer allocation then iteration causes segmentation fault

From Dev

Segmentation fault - printf value from pointer to pointer

From Dev

Segmentation fault while using pointer to pointer to a char

From Dev

Pointer incrementation causing segmentation fault

From Dev

Segmentation fault: Pointer to an array of string

From Dev

Segmentation Fault While Checking Pointer

From Dev

Pointer of a struct with vector - Segmentation Fault

From Dev

Segmentation fault: Pointer to an array of string

From Dev

Struct pointer array segmentation fault

From Dev

Segmentation fault in double pointer looping

From Dev

segmentation fault in passing a char* pointer

From Dev

Segmentation fault on malloc for double pointer

From Dev

Segmentation fault in C. Trying to swap two values using pointer

From Dev

Segmentation fault in C while using int pointer argument

From Dev

C segmentation fault when using pointer to structure in a linked list

From Dev

C Segmentation fault in a Circularly Linked List when setting next pointer

From Dev

C passing dynamic array through pointer (Segmentation Fault)

From Dev

Segmentation fault in C. Trying to swap two values using pointer

Related Related

  1. 1

    C array pointer segmentation fault

  2. 2

    Pointer-to-a-pointer in C throws segmentation fault

  3. 3

    Segmentation Fault, pointer issue?

  4. 4

    Segmentation fault on pointer

  5. 5

    Segmentation fault, pointer issue

  6. 6

    segmentation fault when trying to deference pointer : C

  7. 7

    Odd C pointer segmentation fault errors

  8. 8

    Why this pointer got a Segmentation fault C?

  9. 9

    segmentation fault using char pointer (C)

  10. 10

    segmentation fault when trying to deference pointer : C

  11. 11

    Segmentation fault error with pointer array in C

  12. 12

    Pointer to pointer allocation then iteration causes segmentation fault

  13. 13

    Segmentation fault - printf value from pointer to pointer

  14. 14

    Segmentation fault while using pointer to pointer to a char

  15. 15

    Pointer incrementation causing segmentation fault

  16. 16

    Segmentation fault: Pointer to an array of string

  17. 17

    Segmentation Fault While Checking Pointer

  18. 18

    Pointer of a struct with vector - Segmentation Fault

  19. 19

    Segmentation fault: Pointer to an array of string

  20. 20

    Struct pointer array segmentation fault

  21. 21

    Segmentation fault in double pointer looping

  22. 22

    segmentation fault in passing a char* pointer

  23. 23

    Segmentation fault on malloc for double pointer

  24. 24

    Segmentation fault in C. Trying to swap two values using pointer

  25. 25

    Segmentation fault in C while using int pointer argument

  26. 26

    C segmentation fault when using pointer to structure in a linked list

  27. 27

    C Segmentation fault in a Circularly Linked List when setting next pointer

  28. 28

    C passing dynamic array through pointer (Segmentation Fault)

  29. 29

    Segmentation fault in C. Trying to swap two values using pointer

HotTag

Archive