Int ** a [3] [4] and sizeof (a) and int (**) a [3] [4]

Source: Internet
Author: User

BS makes it clear in C ++ programming that the variable name is more binding than the previous one.

Therefore, the following Variable declaration:
Int ** a [3] [4];
The two-dimensional array "[]" of the "int ** type is more binding than" int "and ). This two-dimensional array has a total of 12 members (3 × 4), each member is a pointer int **), and each pointer is 4. If it is a 32-bit computer, other computers ). Therefore, the length of this array is 12 × 4 = 48.

A is an array, not a pointer

Sizeof (a) = sizeof (int **) * 3*4

A is an array, So If sizeof (a) is used to calculate the value, it should be sizeof (int **) * 3*4 = 48

If a is passed to the function as a parameter, it is automatically degraded to an int ** pointer.


Fun (int ** a, int row, int col );
Use sizeof (a) in the function to measure 4 = sizeof (int **)

I think the basic type of a is int **, And the size is naturally 4. [3] [4] has 12 elements. 4*12 is 48.
64-bit machines must be doubled (because the pointer length of 64-bit machines is 4*2 = 8 bytes)

In this example, a is not a pointer, but an array name.
The array name has two internal meanings:
1. The first address of the array. If you define a pointer to the array, it means it)
2. Array occupies the size of type * Number
So when you
Int m_ia [4];
Int * p = m_ia;
Sizeof (m_ia) = 4 * sizeof (int)
Sizeof (p) = 4


The first thing to note
Int ** a [3] [4]
Defines a set of two-dimensional pointer arrays pointing to pointer variables,
That is to say, a pointer array with three rows and four columns is defined. Each Pointer Points to a pointer,
In terms of storage structure, it is an array that stores 12 pointer variables,
The question is, "How many bytes does a occupy ?"
What does a mean here,
The actual meaning of a is an address, indicating the first address of the array a [3] [4,
As an address, a occupies 4 bytes;
A is also a representation of the array a [3] [4,
If sizeof (a) is used to solve the problem, it represents the space occupied by the array a [3] [4,
Instead of the storage space occupied by address,
That is, the space occupied by 12 pointer variables is naturally 48 bytes.
This statement is correct. Here a refers to the array a [3] [4], but if:
Int a [3] [4];
Int * p = & (* a [3] [4]);
Cout <sizeof (p );
Result 4


This article is from the "energy of Combustion Technology" blog, please be sure to keep this source http://boyishachang.blog.51cto.com/3485129/1273754

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.