Hi guyz,
could you please tell me what's the use of pointer to a pointer? specially in function parameters.
Regards,
could you please tell me what's the use of pointer to a pointer? specially in function parameters.
Regards,
int **array; array = new int*[10]; for (int i = 0; i < 10; i++) { array[i] = new int[10]; }
int **array; array = new int*[10]; for (int i = 0; i < 10; i++) { array[i] = new int[10]; }
char *pp; Function(&pp); void Function(char **ppp) { (*ppp) = malloc(20); strcpy(*ppp, "Hellow World"); }
int myMethod(char *inString, int size); int myOtherMethod(char **inString, int *size);
int myMethod(char *inString, int size) { char* tempString = inString; for(int i=0; i<size; i++) { *tempString = 'A'; tempString ++; } return SUCCESS; //where SUCCESS is defined somehwer..... }
int myOtherMethod(char **inString, int *size) { char *tempBuffer = NULL; if(*size > 0) //Notice value AT size { tempBuffer = (char *)malloc(*size); } else { tempBuffer = (char *)malloc(DEFAULT_SIZE); *size = DEFAULT_SIZE; } //Do whatever we need to do with data //point callers pointer to our buffer *inString = tempBuffer; }
Comment