![]() ![]() This is equivalent to testing *p != '\0' or *p != 0 as stated above.ġ When *p evaluates then the value of *p is fetched from memory. When p reaches the end of the string and finds the first '\0' character, the expression *p returns 1 a zero value. So, the expression *p in loop just check that the decimal equivalent of character at the memory address pointed by p is either a zero or non-zero. In C, strings are terminated by a null character '\0'.Įvery character has a decimal equivalent. What does the *p do in the following loop? ![]() Where expr is any expression at all, the compiler essentially acts as if it had been written as if((expr) != 0) When C requires the Boolean value of an expression, a false value is inferred when the expression compares equal to zero, and a true value otherwise. ![]() I understand you are on precipitous learning curve at the moment with pointers in C, but eventually you'll be able to say "I C the point"īefore diving in, I would like to state a simple rule in C regarding an expression
0 Comments
Leave a Reply. |