C expressions and their execution
I have a question about C expression *cmd++='\0'
.
The program looks like this:
void parse(char *cmd, char **arg)
{
while(*cmd!='\0')
{
while(*cmd==' ' || *cmd=='\t'||*cmd=='\n')
*cmd++='\0';
*arg++=cmd;
while(*cmd!='\0'&& *cmd!=' ' && *cmd!='\t' && *cmd!='\n')
cmd++;
}
*arg='\0';
}
Could you explain this to me?
+3
source to share
2 answers
Following operator precedence http://en.cppreference.com/w/c/language/operator_precedence
line
*cmd++='\0';
equivalent to:
*cmd = '\0';
cmd++;
because cmd ++ will return the original value and then increment it, if you want to increment it should be ++ cmd
+2
source to share