0
Plzz explain (*num !='\o')
from line 41 to 78 https://code.sololearn.com/cJza6635d7Ir/?ref=app
2 Respostas
+ 7
It is '\0', the null character.
C-style strings, i.e. const char* are null-terminated. The value held by a C-style string is a pointer pointing to the first character in the character array. The last character in the array is '\0'.
Doing:
while (*num != '\0')
would mean that the loop is executed until the end of the string is reached.
+ 6
Well, that's another story. We have to look into the ASCII value of the character '0'.
The character '0' has an ASCII value of 48.
http://www.asciitable.com/
*num returns a character value pointed by the address stored within num. When we want to convert a numeric character value to it's integer counterpart, it is a norm to minus that character ASCII by 48 (i.e. '0').
Hence, character '1' of ASCII value 49, will be converted to
'1' - '0'
49 - 48
1
What "if (*num -'0' != 0)" literally means, is:
"If the numeric character pointed by num is not 0".
However (!), I believe the notation is redundant here, since we could have easily achieved the same thing via:
if (*num != '0')