Array indices start counting from 0 in C++ so if you have an array of length 3, index 0 will give you the first element and index 2 will give you the last element. Index 3 would be out of bounds.
I know that there for i have written i=1;i<=3 it means it will start from 1 and end on 3.
but main question is that it gives garbage value in addition.
m3.putdata(); will print garbage because the array elements of m3 has not been initialized. Instead of printing from the add function you might want to return a matrix object that you can assign to m3.