I am confused in the basics of pointer and array declaration in C. I want to know the difference between following two statements except that base address to array is assigned to ptr in seconed statement.
int a[2][3]= { (1,2,3),(4,5,6)};
int (*ptr)[3] = &a[0];
Please quote examples to clarify.
What effect do [3] on R side of line 2 has?
You should know operator precedence rules in C: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedencehttp://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence
int (*ptr)[3]as opposed toint * ptr [3]The first one is a pointer (notice * is closer to the var name) to arrays of int of size 3
The second one is equal to
int (*(ptr [3]))which is an array of size 3 on int pointers.You can also use this site: http://cdecl.org/ if you have doubts on how to interpret an expression.