Dynamically allocate array of 2 pointers to functions returning int and taking no argument.
1 2 3 4 5 6 7 8 9 |
int test1() {printf "test1"; return 0;} int test2() {printf "test2"; return 0;} int main(int argc, char* argv[]) { int (*(*f_arr))() = malloc(sizeof(int (*)()) * 2); f_arr[0] = &test1; f_arr[1] = &test1; } |
Statically allocate array of 2 pointers to functions returning int and taking no argument.
1 2 3 4 5 6 7 8 |
int test1() {printf "test1"; return 0;} int test2() {printf "test2"; return 0;} int main(int argc, char* argv[]) { int (*f_arr[2])() = {test1, test2}; return testRunner(f_arr, 2); } |
Statically allocate 2D array of int (*)()
function pointers
1 2 3 4 5 6 7 8 9 10 11 12 |
int test1() {printf "test1"; return 0;} int test2() {printf "test2"; return 0;} int main(int argc, char* argv[]) { int (*fp1[2])() = {test1, test2}; int (*fp2[2])() = {test1, test2}; int (**fpp[2])(); fpp[0] = fp1; fpp[1] = fp2; fpp[0][0](); } |
Basic pointer arithmetics
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
int main(int argc, char* argv[]) { int foo[6] = {0,1,2,3,4,5}; int* pt = foo; printf("These points to the same address:\n"); printf("&foo+1 = %p\n", &foo + 1); printf("foo+6 = %p\n", foo + 6); printf("pt+6 = %p\n", pt + 6); printf("&pt+6 = %p\n", &pt + 6); printf("(char*)pt + 6*sizeof(int) = %p\n", (char*)pt + 6*sizeof(int)); return 0; } |