포인터로 가리키는 메모리 내용 블록을 표시하는 함수를 사용합니다. 하지만 원하는 출력을 얻지 못했습니다, 나는 이것에 새로운 오전, 제발 내가 잘못하면 수정하십시오. 크기 = 3, 요소 = 1,2,3을 입력하면 출력 = 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++;
}
}
출력을 어떻게 받습니까? 너는 무엇을 기대 했는가? 지금까지 어떤 디버깅을 했습니까? –
코드를 형식화하십시오. –
죄송합니다. 편집했습니다. –