hi guys. Here I have a problem with my pointer work. I just started the pointer and can't figure it out quickly. So guys I need your help and really appreciated. I am going to post my code.
int main()
{
int ary[Max];
int *p, *s;
p = &ary[0];
s = &ary[0];
table_addV( p+10, 10, 5);//need to add value 5 from ary[10] to ary[20]
return 0;
}
void table_addV(int *p, int size, int val)
{
int count;
One problem is your last bit where you print *(p+count). Note that p passed into function does not point to the beginning of ary. So when you try to print Max elements after p, you go out of bounds.
What does the error say?
(unrelated note: p = &ary[0]; is equivalent to p = ary;)
it print out the junk values at the end and the addition is also done in the wrong indexes of array. actually it should add the value from arrays of 10 to arrays of 20. ie. ary[10] to ary[20]. here i am pasting my output.