I'm new in programming and learning about pointers in array. I'm a bit confused right now. Have a look at the program below:
#include <stdio.h>
int fun();
int main()
{
int num[3][3]={23,32,478,55,0,56,25,13, 80};
printf("%d\n",*(*(num+0)+1));
fun(num);
printf("%d\n", *(*(num+0)+1));
*(*(num+0)+0)=23;
printf("%d\n",*(*(num+0)));
return 0;
}
int fun(*p) // Compilation error
{
*(p+0)=0;
return 0;
}
This was the program written in my teacher's notes. Here in the main()
function, in the printf()
function dereference operator is being used two times because num
is pointer to array so first time dereference operator will give pointer to int
and then second one will give the value at which the pointer is pointing to.
My question is that when I'm passing the array name as argument to the function fun()
then why *p
is used; why not **p
as num
is a pointer to array?
Second thing why *(p+0)
is used to change the value of zeroth element of the array; why not *(*(p+0)+0)=0
as in the main()
function *(*(num+0)+0)
is used to change the value of zeroth element?
The whole thing is very confusing for me but I have to understand it anyway. I have searched about this and found that there is a difference between pointer to array and pointer to pointer but I couldn't understand much.