The "trap" in which the array name takes the arithmetic operation of the address

Source: Internet
Author: User

The "trap" in which the array name takes the arithmetic operation of the address




Look directly at the code:

#include <stdio.h>int main () {int array[5];p rintf ("Array      :%p\n", array);p rintf ("Array  + 2:%p\n", array+ 2);p rintf ("&array + 2:%p\n", &array+2); return 0;}


The program output is:


Array name is pointer array is not good to speak of, but the number of &array to address the array, get a pointer to the entire arrays, note that this is not only a pointer to the first element, although the two (array and &array) are consistent numerically.

The addition and subtraction of the &array pointer is based on the entire array size, where the size of the array is 5, then &array + 2

Is twice times the size of the entire array, i.e. 0x7fff8423890 + 0x14 * 2;









The "trap" in which the array name takes the arithmetic operation of the address

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.