The difference between an array name and a group name address, a pointer array, and a set of pointers

Source: Internet
Author: User

firstly, We first analyze the difference between the array name and the address of the group Name.

We all know that the array name is the first address of the array, but what is the address of the group name? Look at the next procedure and you'll Understand.

#include "stdafx.h"
#include <stdio.h>
Using namespace std;
void Main ()
{
int a[5];
printf ("%d\n", a);
printf ("%d\n", &a);
printf ("%d\n", A + 1);
printf ("%d\n", &a + 1);
printf ("%d\n", &a[0] + 1);
printf ("next determine the byte size of array A and &a \ n");
printf ("%d\n", sizeof (a));
printf ("%d\n", sizeof (a));
While (1);
}

Analysis: by the running results, we know that the memory address of the array name A and &a is the same, we have known a=&a[0], so there is a+1 point to the next element in the array (that is, the first address 2751180 based on the number of bytes plus int 4).

however, instead of taking the address of constant a, &a represents the address of the ARRAY. Although the memory addresses of a and &a are the same, their meanings are different, the former represents only the first address of the array, which represents the entire array, and his input unit is the byte length of the entire array (4*5=20), so the memory address of &a+1 is 2751200. In addition, when using sizeof, because it is a keyword, not a function, the array is not automatically converted to pointers, resulting in the length of the array (4*5=20). PS: if it is (int) a+1 then the result is 27511801;

two, the difference between an array pointer and an array of Pointers.

the array pointer int (*parray) [10]=&arr; First () has a higher precedence, so Parray is a pointer to a shaped one-dimensional array with a length of 10, such as an int arr[10]={ 0,1,2,3,4,5,6,7,8,9};

To assign a two-dimensional array to a pointer, you should assign this value:
int a[3][4];
int (*p) [4]; The statement defines an array pointer to a one-dimensional array with 4 Elements.
p=a; Assign the first address of the two-dimensional array to p, i.e. a[0] or &a[0][0]
p++; After the statement executes, that is, P=p+1;p crosses line a[0][] points to the line a[1][]

So an array pointer is also called a pointer to a one-dimensional array, also known as a row pointer.

pointer array int *parray[10] [] precedence high, combined with Parray to become an array, and then by int* Description This is an integer pointer array, which has 10 pointer-type array elements,

The difference between an array name and a group name address, a pointer array, and a set of pointers

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.