C Primer Plus note3, primerplusnote3

Source: Internet
Author: User

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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.