

") First of all, lets inspect what exactly is the for-loop supposed to do! (The post style is motivated by Donald Knuth's phrase "Science is what we understand well enough to explain to a computer. I'll try to explain all necessary aspects by referencing the ISO/IEC:9899 (emphasis mine)- C99 standard. Ritchie would say: Let's do it with the power of assembly language and the convenience of … assembly language. This value is the value of expression *p. 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 On the 3rd line I added the chars of your string for reference.Normally you would see garbage (seemingly random values)

Then you see a few more null characters because I built in debug mode and the compiler zero-initialized. After that you have the string's null character 0x00. The last char in your string is t with hex value of 0x74.
