I am writing a program to just check what pointers do. But I get a segmentation fault(core dumped) message when I seem to have more than two pointers. I have checked for solutions online but the segmentation faults that are dealt with seem to be completely different to this problem.
#include<stdio.h>
int main()
{
  int x=3,y=3;
  int *p1, *p2, *p3;
   p1=&x;
  *p2=x;
   p3=&x;
  printf("%d\n",*p1);
  printf("%d\n",*p2);
  printf("%p\n",p1);
  printf("%p\n",p2);
  printf("%p\n",p3);
 return 0;
}
But if I have just two pointers nothing seems to be wrong. Like if I comment out all the sections related to one pointer(except declaring and initializing) it seems to work fine.
Also I am using ubuntu 16.04(if it is somehow important).
Can anyone please explain why this is happening.
 
    