You should also realise that on return from
fun
you will be back to your original
p1
and
p2
which are uninitialised. To achieve what you are trying to do you should send
p1
and
p2
as references, or add another level of indirection thus:
void fun(int*& p1, int*& p2, int&s)
{
int size;
cin>>size;
s=size;
p1 = new int[size];
p2 = new int[size];
...
void fun(int** p1, int** p2, int&s)
{
int size;
cin>>size
s=size;
*p1 = new int[size];
*p2 = new int[size];
...