You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LearnCCpp/practice/lc_functionPointers.c

37 lines
777 B

#include <stdio.h>
#include <stdlib.h>
void someFunction(int arg)
{
printf("This is someFunction being called and arg is: %d\n", arg);
printf("Now, leaving the funciton!\n");
}
int compare(const void* left, const void* right)
{
return (*(int*)right - *(int*)left);
}
int main()
{
void (*pf)(int);
pf = &someFunction;
printf("We are about to call someFunction() using a pointer!\n");
(pf)(5);
printf("Wow that was cool!");
int (*cmp)(const void*, const void*);
cmp = &compare;
int iarray[] = {1,2,3,4,7,5,6,9,8};
qsort(iarray, sizeof(iarray) / sizeof(*iarray), sizeof(*iarray), cmp);
int c = 0;
while (c < sizeof(iarray) / sizeof(*iarray))
{
printf("%d\t", iarray[c]);
c++;
}
return 0;
}