Note the C++ does not support constructs like
cin>>sizeofarray;int array1[sizeofarray];
C++ native arrays need to have a size that is known at compile time, so the compiler can allocate memory for it at compile time. If you want to have an array that you can re-size at runtime you should use std::vector<>. For example:
cin >> sizeofarray;
std::vector<int> array1 (sizeofarray);
</int>
The same applies to your arrays array2 and answer.
The next error is that you don't reset i and j before entering the while loop:
while(array1[i]!=NULL && array2[j]!=NULL)
Hence, i and j will still have the value of sizeofarray+1 and you will be accessing elements that are out of bounds.
The condition in that while is the next problem. It looks like you are trying to test whether array elements contain a null pointer. But your array contain simple int values. Hence the comparison with NULL does not make sense. If you want to test whether i or j have left the upper array boundary you should compare them with sizeofarray.
Finally, the last i++ and j++ don't appear right to me. Run your program in a debugger and you will see what I mean.