Working with Primitive Data Types

Làm việc với nguyên thủy Các loại dữ liệu C # có một số được xây dựng trong các loại được gọi là kiểu dữ liệu thô. Bảng sau liệt kê các thông dụng nhất kiểu dữ liệu thô trong C #, và phạm vi của các giá trị mà bạn có thể lưu trữ trong đó. | Working with Primitive Data Types C has a number of built-in types called primitive data types. The following table lists the most commonly used primitive data types in C and the ranges of values that you can store in them. Data type int Description Whole numbers Size bits 32 Range - 231 through 231 - 1 Sample usage int count count 42 long Whole numbers bigger range 64 - 263 through 263 - 1 long wait wait 42L float Floating-point numbers 32 x 1038 float away away double Double precision more accurate floating-point numbers 64 x 10308 double trouble trouble decimal Monetary values 128 28 significant figures decimal coin coin string Sequence of characters 16 bits per character Not applicable string vest vest 42 char bool Single character Boolean 16 8 0 through 216 - 1 true or false char grill grill 4 bool teeth teeth false The value of 216 is 32 768 the value of 231 is 2 147 483 648 and the value of 263 is 9 223 372 036 854 775 808. Unassigned Local Variables When you declare a variable it contains a random value until you assign a value to it. This behavior was a rich source of bugs in C and C programs that created a variable and used it as a source of information before giving it a value. C does not allow you to use an unassigned variable. You must assign a value to a variable before you can use it otherwise your program will not compile. This requirement is called the Definite Assignment Rule. For example the following statements will generate a compile-time error because age is unassigned int age age compile time error Displaying Primitive Data Type Values In the following exercise you ll use a C program named PrimitiveDataTypes to demonstrate how several primitive data types work. Display primitive data type values 1. Start Visual Studio 2005. 2. On the File menu point to Open and then click Project Solution. The Open Project dialog box appears. 3. Move to the Microsoft Press Visual CSharp Step by Step Chapter 2 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
39    83    1    15-05-2024
Đã 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.