The address of the array name, and the discussion of the address of the group name

Source: Internet
Author: User

The discovery of this problem is found in the following code:

#include <stdio.h>int main () {int arr[2]={1,2};    printf ("%p", arr);    printf ("%p", &arr); return 0;}

After running, we find that the address of the array name itself and the address of the group name are stored exactly the same, we understand the array name as a const pointer (the array name can only be used as an rvalue, not an lvalue), and what is &arr?

I tried to add the following code to the previous code:

printf ("%p\n", arr+1); printf ("%p\n", (&arr) +1);

It is found in the display window that this shift operation by pointers is more peculiar:

The first one is shifted according to an int size.

The second one is shifted according to a sizeof (a).

This shows that, first of all, they are pointers, the pointer has two parts, one is the stored type, and the other is the address of the memory, above the actual phenomenon that ARR itself is a pointer to the first element of the array, whose pointer type is int*, the second pointer to the operation of the address is a type of int[2]* The pointer.

A freshman who has just entered this field, if there is a mistake, many advice.

This article is from the "12040732" blog, please be sure to keep this source http://12050732.blog.51cto.com/12040732/1883389

The address of the array name, and the discussion of the address of the group name

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.