TAILIEUCHUNG - the ansi c programming phần 5

Năm 1978, Ritchie và Brian Kernighan xuất bản lần đầu cuốn The C Programming Language. Sách này được những người lập trình biết tới như là "K&R", được dùng trong nghiều năm như là một đặc tả không chính thức của C. Phiên bản C mà cuốn sách đó đề cập thường được gọi là "K&R C". (Lần xuất bản thứ hai của cuốn này cũng bao gồm chuẩn ANSI C) | 85 before call to alloc allocp allocbuf - ---- in use --- - - ---------- free --------- after call to alloc allocbuf - -------- in use ---------- - ------ free ---- define ALLOCSIZE 10000 size of available space static char allocbuf ALLOCSIZE storage for alloc static char allocp allocbuf next free position char alloc int n return pointer to n characters if allocbuf ALLOCSIZE - allocp n it fits allocp n return allocp - n old p else not enough room return 0 void afree char p free storage pointed to by p __ if p allocbuf p allocbuf ALLOCSIZE allocp p In general a pointer can be initialized just as any other variable can though normally the only meaningful values are zero or an expression involving the address of previously defined data of appropriate type. The declaration static char allocp allocbuf defines allocp to be a character pointer and initializes it to point to the beginning of allocbuf which is the next free position when the program starts. This could also have been written static char allocp allocbuf 0 since the array name is the address of the zeroth element. The test if allocbuf ALLOCSIZE - allocp n it fits checks if there enough room to satisfy a request for n characters. If there is the new value of allocp would be at most one beyond the end of allocbuf. If the request can be satisfied alloc returns a pointer to the beginning of a block of characters notice the declaration of the function itself . If not alloc must return some signal that there is no space left. C guarantees that zero is never a valid address for data so a return value of zero can be used to signal an abnormal event in this case no space. Pointers and integers are not interchangeable. Zero is the sole exception the constant zero may be assigned to a pointer and a pointer may be compared with the constant zero. The symbolic constant NULL is often used in place of zero as a mnemonic to indicate more clearly 86 that this is a special value for a pointer. NULL is defined in . We .

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.