Module 7 More Data Types and Operators

A variable declared with the const modifier cannot have its value changed during the execution of your program. Thus, a const “variable” isn’t really variable! You can give a variable declared as const an initial value, however. For example, const int max_users = 9; creates an int variable called max_users that contains the value 9. This variable can be used in expressions like any other variable, but its value cannot be modified by your program. | Module 7 More Data Types and Operators Table of Contents CRITICAL SKILL The const and volatile CRITICAL SKILL CRITICAL SKILL static CRITICAL SKILL register CRITICAL SKILL CRITICAL SKILL CRITICAL SKILL The Shift CRITICAL SKILL The CRITICAL SKILL The Comma CRITICAL SKILL Compound CRITICAL SKILL Using This module returns to the topics of data types and operators. In addition to the data types that you have been using so far C supports several others. Some of these consist of modifiers added to the types you already know about. Other data types include enumerations and typedefs. C also provides several additional operators that greatly expand the range of programming tasks to which C can be applied. These operators include the bitwise shift and sizeof operators. 1 C A Beginner s Guide by Herbert Schildt CRITICAL SKILL The const and volatile Qualifiers C has two type qualifiers that affect the ways in which variables can be accessed or modified. These modifiers are const and volatile. Formally called the cv-qualifiers they precede the base type when a variable is declared. const A variable declared with the const modifier cannot have its value changed during the execution of your program. Thus a const variable isn t really variable You can give a variable declared as const an initial value however. For example const int max_users 9 creates an int variable called max_users that contains the value 9. This variable can be used in expressions like any other variable but its value cannot be modified by your program. A common use of const is to create a named constant. Often programs require the same value for many different purposes. For example a program might have several different arrays that are all the same size. In this case you can specify the size of the arrays using a const variable.

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.