Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions basicFunctionPointers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<stdio.h>
/**
* 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));
}