关于C语言中的二维数组有几个问题。
If I create an two dimensional array:
int c[5][25];
Then create a pointer to the beginning of the array:
int *p = c;
Edit: Changing the second line to:
int (*p)[25] = c;
worked. Will this still let me access the array in the following questions?
Would
*(c+26)
access the array atc[1][1]
?I know in a one dimensional array like the following:
double *p; double balance[10]; p = balance;
*(balance + 4)
is the same asbalance[4]
, but wasn't sure if the memory is assigned "back to back" for a 2D array.Can you access
c[1][1]
by doing something likec[2][-24]
?Would be an odd way to do it, but I couldn't find anything addressing that specific scenario.
Would you be able to access
c[1][1]
by the statementp[1][1]
?My guess would be no, since p is a pointer array.
Saw these examples a while ago and wrote them down, but don't remember if they are correct or not:
1[c[1]]; 26[p];
Would either of those be equivalent to
c[1][1]
?
我知道很多这方面的内容都很基础,但我在网上找不到针对这些具体情况的资料。
谢谢!
c[0][24]
可能会被c[1][0]
所跟随,但并没有什么保证。我想编译器可以自由选择如何存储这些矩阵,因此做出假设可能会导致未定义的行为。 - Havenardmain()
中参数argv
的情况。如果以这种方式进行,则无法像那样按顺序访问值。 - Havenard