pointers - In C, what does a variable declaration with two asterisks (**) mean? -
i working c , i'm bit rusty. aware * has 3 uses:
- declaring pointer.
- dereferencing pointer.
- multiplication
however, mean when there 2 asterisks (**) before variable declaration:
char **apointer = ... thanks,
scott
it declares pointer char pointer.
the usage of such pointer such things like:
void setcharpointertox(char ** character) { *character = "x"; //using dereference operator (*) value character points (in case char pointer } char *y; setcharpointertox(&y); //using address-of (&) operator here printf("%s", y); //x here's example:
char *original = "awesomeness"; char **pointer_to_original = &original; (*pointer_to_original) = "is awesome"; printf("%s", original); //is awesome use of ** arrays:
char** array = malloc(sizeof(*array) * 2); //2 elements (*array) = "hey"; //equivalent array[0] *(array + 1) = "there"; //array[1] printf("%s", array[1]); //outputs there the [] operator on arrays pointer arithmetic on front pointer, so, way array[1] evaluated follows:
array[1] == *(array + 1); this 1 of reasons why array indices start 0, because:
array[0] == *(array + 0) == *(array);
Comments
Post a Comment