There are some problems with your code.
First, const char *x = "abc" initializes x a pointer value, sometimes indicating read-only in the executable file zone, and tries to initialize by indirectness, therefore *x = something will be segfault due to the lack of write permission in this segment .
Next, x = malloc(0) is the correct call and the only valid operation you can do with the returned x pointer is free(x) - read the malloc man page.
If the size is 0, malloc () returns either NULL or a unique pointer to a value that can subsequently be successfully passed to free ()
Finally, your code is rewritten like this: suppose you do x in the write zone.
void foo() { char*a,*b; a=calloc(100,1); b=calloc(100,1); memcpy(b,"",4); printf("%p %p `%s `%s\n",a,b,a,b); loop: *a=*b; if (!*b) goto end; /* sequence point after controlling expression of `while`*/ a=a+1; b=b+1; goto loop; end: a=a+1; b=b+1; printf("%p %p `%s `%s\n",a,b,a,b); } int main() { char*a,*b; a=calloc(100,1); b=calloc(100,1); memcpy(b,"",4); printf("%p %p `%s `%s\n",a,b,a,b); while(*a++=*b++); printf("%p %p `%s `%s\n",a,b,a,b); foo(); return 0; }
The only problem here is evaluating the state of the while statement.
6.8.5.1 while statement
1 Evaluation of the control expression takes place before each execution of the body of the cycle.