1.7 c of the pointer

pointer

  • * Pointer variable that represents the variable P P referred to, which is variable a.
  • Why do we need a pointer?
    The purpose of existence is an indirect pointer access. Once you have a pointer, we do not have access to a variable only be accessed via a variable name. And by p = & a; * p = xxx in such a way to indirectly access the variable a.
  • Two important operators: & * and
  • And fixed pointers initialized
    pointer since it is a variable, then certainly you can define and initialize
    the first: first define and then assign
    int p; // define a pointer variable p
    p = & A; // p assigned to
    the second: Definition initialization while
    int
    P = & a; // the same effect as the above two
    pointer when, * P represents the pointer to a variable that points to the variable P.

    int a = 23;
    int *p;

    P=&a;

    p = 111; this corresponds to 111 = A
    the printf (, A "D% = A \ n-.")
    : pointer symbol. When the pointer needle symbol definitions and pointer operations, analytical methods are different.
    int P; defined pointer variable p, where p is not representative of the meaning of the pointer variable pointer variable P points to, when you define here meaning to tell the compiler P is a pointer.
    When using the pointer,
    p represents the pointer variable p points to that variable.
    1.7 c of the pointer
    Full variable pointer is a pointer to a variable whose essence is c language. This variable is special, usually his value will be assigned an address value of a variable (P = & a), then we can use in such a way that variable indirect access * p p points.

  • Essentially pointer variable is a variable, the type of the pointer variable belonging to a pointer type
  • Initial pointers and arrays combined
    array name: doing the right values, the first element of the array name indicates the address of the array, it can be copied directly to the pointer.
    If there int a [5];
    the a and & a [0] represents an array element have a [0] is the first address.
    And & a said first address of the array.
    Note: The address and the first address of the first element of the array of arrays are different. The former is the address of an array element, which is a whole array of addresses. Meaning two different things, but the values are the same. Based on the above, we know that you can use a pointer to the first element of the array, so that you can access by way of indirect access to individually with each array element, so there are two ways to access the array.
    For example: int A [. 5]; int P; P = A;
    manner array accessed sequentially: a [0] a [1 ] a [2] a [3] a [4]
    pointer manner accessed sequentially:
    P (P + 1'd) (P + 2) (P +. 3) (P +. 4)
  • ++ pointer and - symbols operation.
    Itself is a pointer variable, and therefore can be operated. However, since the pointer variable is itself an address stored values of other variables, so the value * /%, etc. operations are meaningless. Pointer variable + 1, -1 is meaningless, subtracting two pointer variables are meaningful. +1 represents the pointer to move rearwardly a lattice grid, -1 move the pointer points to a lattice grid forwardly.
    1.7 c of the pointer

Guess you like

Origin blog.51cto.com/14762640/2484820