C Primer Plus note3, primerplusnote3
Why does the program exit when q is input in the source code above?
While (Condition Statement), status = 1 is a condition statement. As long as the status is not 0, the condition of status = 1 is met, and the program runs the block in the while loop.
According to the rule that the scanf () function reads the input, "% ld" is to read a long integer data, so scanf () the function wants to find a numeric character or a symbol (+ or-). If it finds a number or character, it saves the character and then reads the next character, it has been read for 4 characters (the ld long integer in my compiler is 4 bytes) until now. If the scanf () function encounters non-numeric or non-symbolic characters within the four characters, it will stop reading. Assign the previously read characters to the variables. This explanation can be viewed in the C Primer Plus Sixth Edition Chinese Version book detailed introduction to scanf () function read character rules, in the book 94 page title 1. from the scanf () perspective. If you are interested, read the ebook.
Why is the status equal to 0 when q is entered?
Because the scanf () function does not read numeric characters or symbols (+ or-), a 0 value is returned. Title of page 95 in C Primer Plus (Sixth Edition) 3. Return Value of scanf ()