1. Trang chủ
  2. » Công Nghệ Thông Tin

Mikael olsson c++ quick syntax reference 2013

108 372 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 108
Dung lượng 1,96 MB

Nội dung

Đây là quyển sách tiếng anh về lĩnh vực công nghệ thông tin cho sinh viên và những ai có đam mê. Quyển sách này trình về lý thuyết ,phương pháp lập trình cho ngôn ngữ C và C++.

[...]... null pointer   17 Chapter 6 References References allow a programmer to create a new name for a variable They provide a simpler, safer and less powerful alternative to pointers Creating references A reference is declared in the same way as a regular variable, except that an ampersand is appended between the data type and the variable name Furthermore, at the same time as the reference is declared it must... r = x; // r is an alias to x int &s = x; // alternative syntax   Once the reference has been assigned, or seated, it can never be reseated to another variable The reference has in effect become an alias for the variable and can be used exactly as though it was the original variable   r = 10; // assigns value to r/x  References and pointers A reference is similar to a pointer that always points to the... another variable, a reference is only an alias and does not have an address of its own   int* ptr = &x; // ptr assigned address to x  Reference and pointer guideline Generally, whenever a pointer does not need to be reassigned a reference should be used instead, because a reference is safer than a pointer since it must always refer to a variable This means that there is no need to check if a reference refers... variable This means that there is no need to check if a reference refers to null, as should be done 19 CHAPTER 6 ■ References with pointers It is possible for a reference to be invalid – for example when a reference refers to a null pointer – but it is much easier to avoid this kind of mistake with references than it is with pointers   int* ptr = 0; // null pointer int& ref = *ptr; ref = 10; // segmentation... type change(x); // value is passed cout . myChar = 0; // -1 28 to +127 short myShort = 0; // -3 2768 to +32767 int myInt = 0; // -2 ^31 to +2^3 1-1 long myLong = 0; // -2 ^31 to +2^3 1-1 Many C++ compilers. 0; // -1 28 to +127 signed short myShort = 0; // -3 2768 to +32767 signed int myInt = 0; // -2 ^31 to +2^3 1-1 signed long myLong = 0; // -2 ^31 to +2^3 1-1 signed

Ngày đăng: 19/03/2014, 14:11