Dynamic array parameters

xiaoxiao2021-03-06  24

Q: About the two-dimensional array as a function of the parameters of the function. Main Solution: Liem Author: Naturemickey Thank: MYLOVE0618, LIEM, LW1A2, IDAU7, PCBOYXHY review: Polarislee Community Correspondence: View A: For example: int A [3] [4]; send A as a parameter A function: func (a), there is no problem with only this form: Void func (int b [】 [4]); but if it is as follows: Void func (int * b); there is error in DEVCPP; in VC; There is Warning, but you can get the right result. There is a problem with: (1). A is an int ** type, but in the VC in the VC, it can also get the correct result (* (B 2) in the function, VC is understood as a Integer, and is an integer corresponding to the A [0] [1]); (2). To write a common interface for all int [] [], it seems impossible because the function of the function There must be a number in []. This (2) is the key issue I want to ask, how to write a universal interface (for example: INT [] [])? --------------------- ------------------------------------------ strictly, the variable A is not ( INT **) The secondary pointer type, but an array type. Definition Int a [3] [4] is actually the same as the following definition method, namely: typedef int arraysingledegree [4]; arraysingledegree a [3]; meaning: Variable A is a three elements Array, where each element type is a one-dimensional array (the one-dimensional array has four elements, the specific type Int). If you don't understand the above words, you can imagine the one-dimensional array imagination as a structure. In this way, a two-dimensional array is actually equivalent to a "structural" array, but the structure here is an array. In fact, structural and one-dimensional arrays can be considered in physical storage. The above one-dimensional array type ArraysingLedeGree is equivalent to a structural variable definition: typedef struct tagarrayasstruct {int item1; int IItem2; int it, int IITEM4;} arrayasstruct; class ratio, you can help you Understanding. If you understand the two-dimensional array, you can easily distinguish between the secondary pointer. The content of the secondary pointer variable is the address of a first-level pointer variable. Since the primary pointer variable can point to the first address of any length of one-dimensional array, the secondary pointer variable is not equivalent to any two-dimensional array. In fact, once a two-dimensional array is defined, the length of its corresponding pseudo type is determined by the length of the one-dimensional array.

转载请注明原文地址:https://www.9cbs.com/read-41398.html

New Post(0)