The most powerful of C language-pointer

Source: Internet
Author: User

The most powerful of C language-pointer
Pointers are inseparable from addresses. When we mention pointers, we should think of addresses, because in C language, the value of pointer variables is an address. With this value, it can point to the memory location of the address, you can also use this pointer variable to access the content of the memory location. The method for defining a pointer variable is the same as that of other variables: int * a; char * B ;... here, pointer variable a points to the integer pointer, where the value of a is the address of the first byte of the four bytes of the integer space to which it points; B is a pointer to the struct type, the value of B is the address of this character. Initialize the pointer: int a = 123; int * p = & a; int * pi; p = & a; here the integer variable a is defined, define pointers p and pi. They all point to a. The above two initialization methods both point to. Pointer operation: the process of accessing the address pointed to by a pointer is called indirect access or the unreferenced pointer. Its operator is *. For example, the following definition defines int a = 12; int B; int * p; p = & a; B = * p; defines the pointer p, which points to variable, if you want to assign the value of a to B, you can use the pointer p to unreference the pointer p * p to obtain the content of the address pointed to by p, you can assign the value of a to B. Pointer and array: the value of the array name is a pointer constant, that is, the address of the first element of the array. At this time, it is equivalent to unreferencing the pointer and accessing the array by subscript, we can think that the subscript access operator [] and the quote operator * can be used with each other. Int arr [5] = {1, 2, 3, 4, 5}; the value of arr [0] is 1 * the value of arr is also 1, which is equivalent to * (arr + 0)

Related Article

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.