SIGSEV on strcmp of memset string

后端 未结 3 469
自闭症患者
自闭症患者 2021-01-29 12:29

In the following program, i am expecting the for loop to stop after 3 elements. But it keeps on going indefinitely and fails later on with a coredump.

  1. is mal
3条回答
  •  有刺的猬
    2021-01-29 13:04

    for(i=0;strcmp("",str[i])!=0;i++)
    

    You do dereference the unitialized pointer

    for(i=0;str[i];i++)
    

    But it will not work as this

    memset(str,0,10);
    

    Does not initialize the whole array

    memset(str,0,10*sizeof(char *);
    

提交回复
热议问题