What exactly performs the following return statement?

1
    return *s && strchr(delimiter, *s);

I have seen that it is used in javascript as an abbreviation of:

       if(param 1) return param2;
        else return param1;

But it is not clear to me if its use is the same.

    
asked by Diego 21.09.2017 в 18:10
source

1 answer

1

There are 4 parts, well differentiated:

*s

Get the value pointed to by the pointer s .

&&

If the previous value is not 0 , continue

strchr( delimiter, *s );

Get the value of the call to this function (which, by the way, looks for a character in a array of them, pointed to by the variable delimiter The character is pointed by s ).

return

Returns the result of all the above. In other words:

if( *s ) {
  return strchr( delimiter, *s );
} else {
  return *s;
}

That could also be written as

return *s ? strchr( delimiter, *s ) : *s;

or

return *s ? strchr( delimiter, *s ) : 0;

Although I would use this last form.

As you can see, it's the same as for Javascript.

    
answered by 21.09.2017 / 18:30
source