int print(int **a, int m, int n)
{
int i, j, sum = 0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum = sum + *((a + i*n) + j);
}
}
return sum;
}
I got a garbage value instead of sum of the array elements. When I type-casted as
sum = sum + (int )*((a + i*n) + m));
I'm getting a correct answer. Why is that? But this method won't work for modifying the array elements. How can I do that? Please check this link for reference. http://ideone.com/VRVAxW