A question I accidentally saw today

Source: Internet
Author: User

Today, I accidentally saw a post posted by my dear friend, saying that no one has made it in the three provinces in northeast China.

What is the result of the following C code running in VC ++ 6.0? Describe the cause in detail.
 

# Include <stdio. h>
Int main ()
{
Int a [5] = {1, 2, 3, 4, 5 };
Int * ptr1 = (int *) (& a + 1 );
Int * ptr2 = (int *) (int) a + 1 );
Printf ("% x, % x", ptr1 [-1], * ptr2 );
Return 0;
}

The first one is the question of & a + 1. It is obvious that the answer to ptr1 [-1] is "5 ".

The second question * ptr2 is very interesting.

0x00000001 and 0x00000002 are arranged in the memory as follows:

0x0000000 and 0x20000000

The two rows are 0x0100000020000000 together.

So (int) the pointer to a + 1 is 0x20000000 in the memory.

This topic is quite interesting. Let's take a look at it. ^_^

If you want to recruit embedded students, you can still go to Southwest University of Science and Technology to check out. Although not all of them have done this, some people can do it. Haha, I am not looking for a job yet... It would be better if we come to our school to test this question ^_^

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.