Also Talk About array A and &

Source: Internet
Author: User

Today I made a question:

 

1 # Include < Stdio. h >
2 Int Main ()
3 {
4 Int A [ 5 ] = { 1 , 2 , 3 , 4 , 5 };
5 Int   * PTR = ( Int * )( & A + 1 );
6 Printf ( " % D " , * ( + 1 ), * (PTR - 1 ));
7 }

 

You can try to see if the answer is the same as you think.

The key to this question is to understand the difference between A and.

A is a constant pointer to the int type.

& A is a pointer to int [5. Equivalent to int (* P) [5] = &;

Int * P = &;

At this time, the VC compiler will prompt a warning: 'int * 'differs in levels of indirection from 'int (*) [5]', that is, the type does not match

After obtaining a non-existent address (& A + 1), The type is forcibly converted to (int *), so * (p-1) points to the last element of.

Please correct us if anything is wrong!

 

 

------------- Walking down the fallen leaves, pursuing my dream

 

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.