TAILIEUCHUNG - the ansi c programming phần 2

Trong các phiên bản trước đây của C, chỉ có những hàm nào trả về một số khác số nguyên mới cần được khai báo trước khi dùng. Một hàm dùng mà không có bất kì sự khai báo nào trước đó được giả thiết là sẽ trả về một số nguyên. | 22 if c n nl if c c n c t state OUT else if state OUT state IN nw printf d d d n nl nw nc Every time the program encounters the first character of a word it counts one more word. The variable state records whether the program is currently in a word or not initially it is not in a word which is assigned the value OUT. We prefer the symbolic constants IN and OUT to the literal values 1 and 0 because they make the program more readable. In a program as tiny as this it makes little difference but in larger programs the increase in clarity is well worth the modest extra effort to write it this way from the beginning. You ll also find that it s easier to make extensive changes in programs where magic numbers appear only as symbolic constants. 23 The line nl nw nc 0 sets all three variables to zero. This is not a special case but a consequence of the fact that an assignment is an expression with the value and assignments associated from right to left. It s as if we had written nl nw nc 0 The operator means OR so the line if c c n c t says if c is a blank or c is a newline or c is a tab . Recall that the escape sequence t is a visible representation of the tab character. There is a corresponding operator for AND its precedence is just higher than . Expressions connected by or are evaluated left to right and it is guaranteed that evaluation will stop as soon as the truth or falsehood is known. If c is a blank there is no need to test whether it is a newline or tab so these tests are not made. This isn t particularly important here but is significant in more complicated situations as we will soon see. The example also shows an else which specifies an alternative action if the condition part of an if statement is false. The general form is if expression statement else statement One and only one of the two statements associated with an if-else is performed. If the expression is true statements is executed if not statement2 is executed. Each statement can be a single statement

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.