Yes, you have found c++ shell. For runnable code samples you can get at it from the gear-wheel icon at the top of the code sample. Go to the Options tab and turn all the warnings on before you try to run: it will tell you that you have a zero-size array.
When you declare
int result[]={};
how big do you think your array is? Its size is zero, and you cannot change that at run time.
If you want, you can declare the array result[] to be suitably large, say
int result[100];
and hope that the intersection of your other two arrays is not bigger.
The values put in result[] are wrong. If you declare result with sufficient size then you can remove line 20 and replace your original lines 22-24 by
1 2 3 4
|
result[resultMax]=data1[i];
resultMax++;
i++;
j++;
|
You cannot relate resultMax to the size of a static array as you tried to do first.
Any output that you get from this at present is more by luck than judgement. All you are doing with the line
resultMax += sizeof(result[i])/sizeof(int);
is
resultMax += 4/4
(assuming an int occupies 4 bytes) or just
resultMax += 1
Your
result
is a zero-size array; result[i] is, therefore, outside array bounds. Since all you are doing with this particular line is asking for the size of an integer here you may well get away with it for finding the number of elements in the intersection. However, if you do try printing out the CONTENTS of result[] after the end of the loop you will be out of luck. If result[] is a zero-size array, then line 20,
result[i] = data1[i];
, is VERY WRONG; it could be writing to memory just about anywhere. Even if you make result[] large enough to hold the whole intersection then this statement will still be wrong - data1[i] is not the ith element of the intersection.
If you do need to store your intersection (and there is nothing in your code at present that requires it) then you would be better using a resizable array - aka a vector<int>. I can assure you that with your code at present the array result[] does NOT store the intersection because (a) it has zero size and (b) even if you did set a larger size then you are putting the intersection elements into the wrong positions in it.