Code:
#include<stdio.h>
#include<stdlib.h>
void createAndFillList(int** ptr,int ninput){
int i;
ptr=malloc(sizeof(int)*ninput);
for(i=0;i<ninput;i++){
printf("enter: ");
scanf("%d",&*(*ptr+i));
}
printf("%p\n",&*ptr);
}
int main(){
int** ptr;
int ninput;
printf("enter how many spaces will be allocated:");
scanf("%d",&ninput);
createAndFillList(ptr,ninput);
printf("%p\n", &ptr);
getch();
free(ptr);
return 0;
}
How to return the value of the address of the first ptr
or ptr + 0
? I tried everything and it seems to crash every time I input more than 1.