下边这段code,可以发现:

1.指针之间赋值时候,不会触发段错误,会给指针赋成NULL

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

2.实际访问时候才会导致段错误

#include <stdio.h>

struct TEST {
    struct TEST *next;
} *ptest;

int main(int argc, char *argv[])
{
    struct TEST **pptest;

   /*此处不会导致段错误*/
pptest = &(ptest->next);
   /*pptest为空*/
if (pptest != NULL) { printf("pptest is not null\n"); } else {
     /*打印出来*/ printf(
"pptest is null\n"); }
   /*此处会导致段错误*/
if (*pptest != NULL) { printf("*pptest is not null\n"); } else { printf("*pptest is null\n"); } return 0; }

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄