Array pointers and arrays of pointers in C language

Source: Internet
Author: User

1. Array pointers: pointers to arrays are array pointers

Let's look at the following code:

#include <stdio.h>int main (void) {    int m[10];    printf ("M =%p, &m =%p\n", M, &m);    printf ("m + 1 =%p, &m + 1 =%p\n", M + 1, &m + 1);    return 0;}

Run the above code to get the results such as:

In the above code, &M is a pointer to an array, and the array pointer, which is exactly equal to m in value, points to the starting address of the same memory. But they are of different types. where M is a pointer to an int * type, and &m points to an array such as int m[10], which is an array pointer, so m + 1 equals sizeof (int), which can be computed (0x0028fefc-0x0028fef8) = 4; &m + 1 corresponds to the addition of sizeof (INT[10]), by the calculation in (0X0028FF20-0X0028FEF8) = 40.

can have the following definition:

int (*p) [Ten] = &m; Here p is an array pointer, and here (*p) The parentheses are required,() the precedence is higher than [], so p is first a pointer, and then points to an array of int [10].

2. Array of pointers: arrays of multiple pointers are arrays of pointers

int *p[10]; This can be compared to the above array pointers. P is first an array, and then the type is a pointer, so p is an array of pointers (with 10 pointers, such as p[0], p[1] ... P[9], each pointer is of type int *), each of its variables can be used to store the address.

Array pointers and arrays of pointers in C language

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.