Pointers in the C language

Source: Internet
Author: User

Let's look at pointers in C + +, which is just an extension

Array pointers

In fact, the main point here is the pointer operation in C + +

  /* Array element pointer:    A variable has an address, an array contains several elements, each array element has a corresponding address, and a    pointer variable can point to an array element (the address of an element is placed in a pointer variable)    A pointer to an array element is an array element whose address    can be pointed to an array element     int a[10]={1,2,3,4,5,6,7,3,2,3} with a pointer variable;        int *p;        p=&a[0]; Equivalence and p=a; equivalent to int *p=a; Equivalence with int*p=&a[0]     Note:    1) The array name A does not represent the entire array, only the address of the first element of the array       p=a is "Assigning the address of the first element of a array to the pointer variable P" instead of "assigning the value of each element of the array A to P"   array Pointers: pointer    array pointers to array elements:    using an array pointer to indirectly access the array pointer's definition of an element array:    int *p; array pointer initialization;     int a[4] ={1,2,3,4};    int *p = a;//array pointer, defines the first address of a pointer variable p assignment array (the address of the first element), p points to the first element of the array        int *p = &a[0];//equivalent to the above sentence  array pointer How to access the elements of the array:    1) p+1 represents the next element to the array    2) p-1 points to the previous element of the array  error: Iterating the array for    (int i=0;i<4; i++) {        printf ( "%d\t", *p++);    }     The misunderstanding of Learning: array name A is a constant equivalent to * (10++)    //array name + + This is the wrong    printf ("*a=%d\n", *a++);//The notation is wrong   */

  

Pointers in the C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.