The C++ Programming Language Third Edition phần 2 pps

102 872 0
The C++ Programming Language Third Edition phần 2 pps

Đ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

Section 5.3.1 Navigating Arrays 93 is equivalent to a traversal using a pointer: v oi d f p(c r v vo id fp ch ar v[]) { f or (c r* p = v *p 0; p fo r ch ar v; p!=0 p++) u se p); us e(*p } The prefix * operator dereferences a pointer so that *p is the character pointed to by p p p,and ++ increments the pointer so that it refers to the next element of the array There is no inherent reason why one version should be faster than the other With modern compilers, identical code should be generated for both examples (see §5.9[8]) Programmers can choose between the versions on logical and aesthetic grounds The result of applying the arithmetic operators +, -, ++, or to pointers depends on the type of the object pointed to When an arithmetic operator is applied to a pointer p of type T p is T*, assumed to point to an element of an array of objects of type T p points to the next element of T; p+1 that array, and p points to the previous element This implies that the integer value of p will p-1 p+1 be s iz eo f(T larger than the integer value of p For example, executing si ze of T) p #i nc lu de in cl ud e io st re am i nt m n () in t ma in { i nt v i[1 0]; in t vi 10 s ho rt v s[1 0]; sh or t vs 10 s td :c ou t

Ngày đăng: 12/08/2014, 19:21

Từ khóa liên quan

Mục lục

  • The C++ Programming Language (Special 3rd Edition)

    • Part I: Basic Facilities

      • Ch5 Pointers, Arrays, and Structures

        • 5.4 Constants

        • 5.5 References

        • 5.6 Pointer to Void

        • 5.7 Structures

        • 5.8 Advice

        • Ch6 Expressions and Statements

          • 6.1 A Desk Calculator

          • 6.2 Operator Summary

          • 6.3 Statement Summary

          • 6.4 Comments and Indentation

          • 6.5 Advice

          • Ch7 Functions

            • 7.1 Function Declarations

            • 7.2 Argument Passing

            • 7.3 Value Return

            • 7.4 Overloaded Function Names

            • 7.5 Default Arguments

            • 7.6 Unspecified Number of Arguments

            • 7.7 Pointer to Function

            • 7.8 Macros

            • 7.9 Advice

            • 7.10 Exercises

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan