私はポインタで指されたメモリの内容のブロックを表示する関数を使用します。 しかし、希望の出力を得られなかった、私はこれに新しいです、私が間違っている場合、私を修正してください。 入力サイズ= 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++;
}
}
どのような出力を得ましたか?あなたは何を期待しましたか?これまでに何をデバッグしましたか? –
コードをフォーマットしてください。 –
申し訳ありません、私はそれを編集しました –