嗨指针递增到 NULL 到字符串的末尾,如下面的代码,但是如果检查它证明是错误的,为什么?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char *p="Hello,"; // after comma NULL is implicit here
char *q;
q=strchr(p,','); // copyied all char from , till null
printf("%s\n",q); // good its print ,
char *temp=strdup(q); // temp contain all string of q
printf("%s\n",temp); // , good
if(temp!=NULL)
{
*temp++='\0'; // overwriting , with NULL and increment pointer which now point to NULL
printf("%s\n",temp); // blank because it is NULL
if(temp==NULL) // bad why this is not true since pointer temp is pointing to NULL?
{
printf("its null\n"); // why i am not getting this
}
}