Segmentation fault while using malloc with char pointers

前端 未结 5 1169
独厮守ぢ
独厮守ぢ 2021-01-22 16:20

I am new to C and learning structs. I am trying to malloc a char pointer with size 30 but it is giving a segmentation fault(core dump). I searched it on the interne

5条回答
  •  走了就别回头了
    2021-01-22 16:55

    Check for NULL values in return of malloc() function.

    Also str *p; < is not initialised.

    initialize p as str *p = malloc(sizeof(str));

提交回复
热议问题