【发布时间】:2015-01-27 22:51:00
【问题描述】:
我想传递一个指向多维数组的指针,因此该值可以保持不被复制。我该怎么做?我也一直在跟踪 int 计数,它每次都有效吗?我需要的数组是内存。该结构体之前已在 main 之外声明过。
struct registers
{
int data;
} registerX, registerY;
void first(int *counter, struct registers* X1, int **m)
{
int value;
printf("Enter the value for the X\n");
scanf("%d", &value);
X1->data = value;
m[*counter][1] = X1->data;
*counter = *counter++;
}
int main()
{
int memory[SIZE][2];
int count = 0;
int choice;
printf("Enter the instruction number:\n");
while(choice != 107)
{
scanf("%d", &choice);
if(choice == 101)
{
memory[count][0] = 101;
first(&count, ®isterX, &memory[count][1]);
}
【问题讨论】:
-
&memory[count][1]是int *。接收int *m, 然后m[*counter][1] = X1->data;-->*m = X1->data;,*counter = *counter++;-->++*counter;或*counter += 1; -
*counter++和++*counter有什么区别?
-
*counter++表示*(counter++)。++用于增量指针。++*counter是增量*counter即(*counter)++。 -
谢谢!真的很有帮助!
-
@BLUEPIXY 除了
++*counter不与(*counter)++相同。
标签: c arrays multidimensional-array call dereference