I'm trying to create a dot product function for a larger project. provec0 and provec1 are the two output ints that are supposed to be the product of the four input ints.
The problem --
Console output
1 2
1976708154
32767
The wanted output is 10, 20 not 1976708154, 32767.
#include <iostream>
usingnamespace std;
int vec0[] = {2,4};
int vec1[] = {3,2};
int vec0_s = sizeof(vec0)/sizeof(*vec0); // Number of elements in vec0
int vec1_s = sizeof(vec1)/sizeof(*vec1); // Number of elements in vec1
int* dotM(int vecA[], int vecB[]);
int main () {
int *provec = dotM(vec0, vec1);
cout << provec[0] << endl; // Prints *vecO
cout << provec[1] << endl; // Prints *(vecO+1)
}
int* dotM(int vecA[], int vecB[]){ // Dot Product Function
int* vecO;
for(int a=0;a < vec0_s; a++){
for(int b=0;b < vec1_s; b++){
*(vecO+a) += vecA[a] * vecB[b];
}
}
return vecO;
}
The dot product (or inner product, or scalar product) of vectors (2,4) and (3,2) is the single number 14. Could you explain what you are actually trying to do.
And why do you need all those pointers? Just use the normal array elements.