Differences between a and & amp; a in the array

Source: Internet
Author: User

 

Recently I have been reading a book on C language in depth. I feel that the relationship between pointers and arrays is quite understandable. Sometimes someone writes a long article about pointers and arrays. Intuition tells me that it is a good article. It must be the result of years of practice and deliberation by the expert. If I can reach the level he understands, then my C language will take another step. But in order to have a profound understanding, I will not read his article, but I will first think about it myself.

Int a [5] = {0, 1, 2, 3, 4}

Int * p1 = a; // define p1 as the first address pointing to the first element of array a, instead of the address pointing to array a. Although the value is the same, the meaning is different.

A + I is not equal to & a + I

A + I = a + I * sizeof (a [0]) and & a + I = a + I * sizeof ()

The running result of the following program is? Www.2cto.com

# Include <stdio. h>

# Include <stdlib. h>

Int main ()

{

Int a [5];

Int * p1 =;

Int * p2 = &;

 

Printf ("% p \ n", );

Printf ("% p \ n", a + 1 );

Printf ("% p \ n", & a + 1 );

 

System ("PAUSE ");

Return 0;

 

 

}

The running result on my machine is: 0022FF20

0022FF24

0022FF34

 

From regecode

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.