Look we wish to allocate memory for an array of 3 integer pointers. so when we do dynamic allocation we always store the result in a pointer to the required data type. for example if you wish to dynamically allocate int arr[3[] u will write :
int *p=malloc(3*sizeof(int)); So now when you do it for an array of integer pointers the result of malloc should point to the first element of the dynamically allocated array. The elements of the array are pointers hence the memory allocated will be saved in a pointer that will correspond to the pointer to the first element. Since the elements are pointers so the result of malloc will be saved to a pointer to a pointer. My sample program which i compiled in Dev C++ is as follows : #include<stdio.h> #include<conio.h> main() { int a,b,c; int **p; p=malloc(3*sizeof(int *)); a=b=c=1; p[0]=&a; p[1]=&b; p[2]=&c; printf("%d %d %d",*p[0],*p[1],*p[2]); getch(); } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/ScQJutsiThgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.