diff --git a/README.md b/README.md index 341baa9..0d058ca 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ These program are written in codeblocks ide for windows. These programs are not - [Recursion](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/Recursion.c) - [Segmentation Fault or Bus Error Demo](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/SegmentationFaultorBusErrorDemo.c) - [Structure](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/Structure.c) +- [Basic Pointers to Functions](https://github.com/gouravthakur39/beginners-C-program-examples/blob/master/basicFunctionPointers.c) - [Swapping 2 Numbers Without a Third Variable or ^](https://github.com/geetanjaliaich/beginners-C-program-examples/blob/FactorialEratosthenes/SwapIntegersWithout3rdVariable(Arithmatic).c) - [Print 100 Prime numbers using Seive of Eratosthenes](https://github.com/geetanjaliaich/beginners-C-program-examples/blob/FactorialEratosthenes/PrimeByEratosthenes.c) - [Palindrome Number](https://github.com/geetanjaliaich/beginners-C-program-examples/blob/FactorialEratosthenes/PalindromeNumber.c) diff --git a/basicFunctionPointers.c b/basicFunctionPointers.c new file mode 100644 index 0000000..86afcbe --- /dev/null +++ b/basicFunctionPointers.c @@ -0,0 +1,27 @@ +#include +/** + * add - adds two numbers + * this function would be called indirectly with function pointers + * @a: integer + * @b: integer + * Return: sum of a and b +*/ +int add(int a, int b) +{ + return (a + b); +} + +/** + * main - entry point + * the main function calls the add function indirectly using function pointers + * Return: 0 (success) +*/ +int main(void) +{ + int (*fptr)(int, int); /* This is the declaration of the function pointer. + this pointer points to a function that takes two integers + as arguments and return an integer */ + + fptr = add; + printf("%d", fptr(1,2)); +} \ No newline at end of file