Wrote a simple swap program, works well; But gives a Segmentation Fault after printing everything.
#include <stdio.h>
void swap(int* p1,int* p2){
int* temp;
*temp = *p1;
*p1 = *p2;
*p2 = *temp;
}
int main(){
int a,b;
a = 9; b = 8;
printf("%d %d \n",a,b);
swap(&a,&b);
printf("%d %d \n",a,b);
return 0;
}
Output:
9 8
8 9
Segmentation fault
Should I simply ignore this and move forward or is there something really strange going on ?