TAILIEUCHUNG - c for engineers and scientists introduction to programming with ansi c phần 5

b. Xác định những chương trình bằng văn bản trong Tập thể dục 1a khi số lượng nhập là 3 và 0, và mã chọn là 3. c. Sửa đổi chương trình bằng văn bản trong Tập thể dục 1a vì vậy mà chia cho 0 là không được phép và một thông điệp thích hợp sẽ được hiển thị khi phân chia như vậy là cố gắng. | Array Initialization 251 If the number of initializers is less than the declared number of elements listed in square brackets the initializers are applied starting with array element zero. Thus in the declaration float length 7 only length 0 length 1 length 2 and length 3 are initialized with the listed values. The other array elements will be initialized to zero. Unfortunately there is no method of either indicating repetition of an initialization value or initializing later array elements without first specifying values for earlier elements. A unique feature of initializers is that the size of an array may be omitted when initializing values are included in the declaration statement. For example the declaration int gallons 16 12 10 14 11 reserves enough storage room for five elements. Similarly the following two declarations are equivalent char codes 6 s a1 m P 1 e char codes s a m p 1 e Both of these declarations set aside six character locations for an array named codes. An interesting and useful simplification can also be used when initializing character arrays. For example the declaration char codes sample no braces or commas uses the string sample to initialize the codes array. Recall that a string is any sequence of characters enclosed in double quotes. This last declaration creates an array named codes having seven elements and fills the array with the seven characters illustrated in Figure 6-6. The first six characters as expected consist of the letters s a m p 1 and e. The last character which is the escape sequence 0 is called the null character. The null character is automatically appended to all strings by the c compiler. This character has an internal storage code that is numerically equal to zero the storage code for the zero character has a numerical value of decimal 48 so the two cannot be confused by the computer and is used as a marker or sentinel to mark the end of a string. As we shall see in Chapter 11 this marker is .

TỪ KHÓA LIÊN QUAN
Đã 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.