C pointer (7) pointer operation

Source: Internet
Author: User

(7) pointer operation

In the previous articles, we have seen the usage scenarios of pointer operations and used multiple pointer operations for verification. Here we will particularly summarize the essential meaning of pointer operations.

In C language, if p, Pa, and Pb are all pointer types, such operations are called pointer operations:

  1.  
  2. , Premise: the PA and Pb types are the same.
Its essence is 1 .. 2. The number of logical storage units instead of the number of physical bytes is obtained. Code Verification
int main(void){int array[] = {1, 2, 3};int *pa = array;int *pb = array + 3;printf("sizeof(pa)...%d\n", sizeof(pa));printf("pb-pa...%d\n", pb - pa);printf("((unsigned)pb-(unsigned)pa)/sizeof(pa)...%d\n", ((unsigned)pb - (unsigned)pa) / sizeof(pa));return 0;}
Run

Of course, it is also possible to interpret pa-Pb as (char *) Pa-(char *) Pb)/sizeof (PA.
The pointer operation summarizes that the pointer stores the address, which is essentially an unsigned integer. For p + 1, it is not simply to move the value of P to a byte. One sentence: Pointer operations are closely dependent on Pointer types.. Therefore, it is important to know the pointer type in Pointer operations. This is why pointer types can be tested using pointer operations.
It must be noted that operations like pa + Pb do not exist!


Column Directory: C pointer

C pointer (7) pointer operation

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.