Home > Back-end >  For help
For help

Time:01-11

The book
Int a, [m] [n].
Int (* p) [n].
P=a or p=a [0]
Here refers to a [0] not row 0 0 of address, please, how can be assigned to p, p row pointer, isn't it,

CodePudding user response:

Stick to your understanding, can't do that assignment,

CodePudding user response:

Strict said p=[0] is a syntax error, if strict syntax check: the type expression should be equal on both sides of the assignment statement or compatible, p=a certificate is the same: a type of=int [m] [n]=int ([m]) [n], because of a one-dimensional array can be considered as a single pointer * [m], so the type=int (*) [n]=p type, and p=a [0] while writing should be p=& amp; A [0], on both sides of the type is equivalent to about type equivalence parsing and prove that refer to "the essence of C + + programming tutorial", to enter the door of the C language, must master the type of the expression parsing, computing and equivalence prove that 80% of the error are related to this, in addition, most of the compiler does not support dynamic multidimensional arrays: directly with m, n 2 d dynamic is not allowed, only allows the first d dynamic,

CodePudding user response:

Understanding and discussion before, please first learn how to observe!
Fyi:
//char (* * x [3] ()) [5]. What type of variable is//x? 
//
/analysis/C statement, the key is to find out what this variable is a (function, Pointers, arrays),
//is the function that is left is his arguments and return values,
//is a pointer that rest is shows that he points to what,
//is the rest of the array is a member of the array is what type,
//parsing rules of C language statement:
//start from the left side of the first identifier, carried out in accordance with the priority, * said is.. Pointer to a const said read-only, volatile variable, array [] says, are () function,
//
//x and [3] is a size of 3 array, the array of each element as a pointer, the pointer to a class of function, this function has no parameters and return type of a pointer, the pointer to a char array size is 5
#include
#include
Char num [5].
Char (* x00 ()) [5] {
Return & amp; Num.
}
Int main () {
Char (* * x [3] ()) [5].//is an array, the size is 3
Char * (* x0) () () [5].//an array of elements, is a function pointer
Char (* x00 () ()) [5].//function prototype, the parameter is null, the return value is a pointer
X000 char (*) [5];//the return value

X0=x00;
X [0]=x0;
X [1]=x0;
X [2]=x0;
Printf (" typeid (x). The name () is % s \ n ", the typeid (x). The name ());
return 0;
}
//the typeid (x). The name () is char (* (__cdecl * *) (void)) [5]

CodePudding user response:

Don't superstitious books, examination questions, teachers, reply;
CPU to superstitions, compiler, debugger, run results,
And please combine "the blind man touched the sun" and "boat out to sea must carry only a compass," try to understand,
Any theory, authority, according to legend, the truth, and the standard, explain, imagination, knowledge... Is not in my eyes!
  • Related