help printing returned int array

ok so i need to write a union and intersection program for two sets of ints. I have it so it would print the ints as it went to start, but i also have to be able to store the final set which is why i need to return it. i've got it to return information, but not right. when i run the program this is what i get....

The union of the sets is....
1 2 3 5 6 7 8 10
The intersection of the sets is....
2 5 10 0x108000890

the 0x108000890 is supposed to be 2 5 10 over again. but instead it just gives me the location of the pointer. i've tried a million different ways to get this, but it's just not working for me. any help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
#include<iostream>
using namespace std;

/* Function prints union of arr1[] and arr2[]
 m is the number of elements in arr1[]
 n is the number of elements in arr2[] */




int* printUnion(int arr1[], int arr2[], int m, int n)
{
    int i = 0, j = 0;
    while(i < m && j < n)
    {
        if(arr1[i] < arr2[j])
            printf(" %d ", arr1[i++]);
        else if(arr2[j] < arr1[i])
            printf(" %d ", arr2[j++]);
        else
        {
            printf(" %d ", arr2[j++]);
            i++;
        }
    }
    
    /* Print remaining elements of the larger array */
    while(i < m)
        printf(" %d ", arr1[i++]);
    while(j < n)
        printf(" %d ", arr2[j++]);
}

int* printIntersection(int arr1[], int arr2[], int m, int n)
{
    int* tempp = new int[10];
    int t=0;
    
    int i = 0, j = 0;
    while(i < m && j < n)
    {
        if(arr1[i] < arr2[j])
            i++;
        else if(arr2[j] < arr1[i])
            j++;
        else /* if arr1[i] == arr2[j] */
        {
            printf(" %d ", arr2[j++]);
            tempp[t]=arr2[j++];
            t++;
            i++;
        }
    }
    return tempp;
}

/* Driver program to test above function */
int main()
{
    int arr1[] = {1, 2, 5, 6, 10};
    int arr2[] = {2, 3, 5, 7, 8, 10};
    int m = sizeof(arr1)/sizeof(arr1[0]);
    int n = sizeof(arr2)/sizeof(arr2[0]);
    cout<<"The union of the sets is...."<< endl;
    printUnion(arr1, arr2, m, n);
    cout<<"The intersection of the sets is...."<< endl;
    cout<<printIntersection(arr1, arr2, m, n);
    return 0;
}
Topic archived. No new replies allowed.