gpt4 book ai didi

c - 在函数中使用指针的指针的正确方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 02:14:08 24 4
gpt4 key购买 nike

<分区>

我使用一个函数来显示指针指向的内存块内容。但是没有得到想要的输出,我是新手,如果我错了请纠正我。当我输入 size =3, element = 1,2,3 时,我只得到 output = 1。

代码如下:

#include <stdio.h>
#include <stdlib.h>

void merge(int **arr1);

int main(void) {
int size1;
printf("Give me the size of first array\n");
scanf("%d", &size1);

int *arr1 = malloc(size1*sizeof(int));
int *p1=arr1;
printf("Give me the elements of first array\n");
int index1;
for(index1 = 0 ; index1<size1; index1++)
scanf("%d", p1++);

merge(&arr1);
return;
}

void merge(int **arr1) {
while(**arr1) //**arr1 is the content of the passed array, if there
// is an int in it, print that out and increment to next one
{
printf("%d", **arr1); // ** is the content and * is the address i think, right?
*arr1++;
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com