hello guys i'm kinda new in here and in c also i've been practising pointers to functions and i've come up with this code :
#include <stdio.h>
#include <stdlib.h>
typedef int (*fptr)(int,int);
void swapp(int*,int*);
int sub(int ,int );
int add(int ,int );
int operation(fptr,int,int);
int main()
{
int n=10,n1=25;
printf("%d+%d=%d",n,n1,compute(add,n,n1));
printf("\n%d-%d=%d",(n>n1)?n:n1,(n<n1)?n:n1,compute(sub,n,n1));
return 0;
}
void swapp(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
int add(int a,int b){
return a+b;
}
int sub(int a,int b){
if(a<b)
swapp(a,b);
return a-b;
}
int compute(fptr operation ,int a,int b){
return operation(a,b);
}
when compiled i get "Segmentation Fault(core duped) can anyone help me debug this? and thx i just can't see anything wrong with the code