+ 4

anyone pls explain this type of declaration "int (*ptr)[5];"

7th Aug 2019, 6:31 PM
Ashwin Raj
Ashwin Raj - avatar
5 Answers
+ 7
as swim said it is a pointer to an array of 5 integers so one array of 5 integers is just one element when I say ptr+1 in this case it will return an address that is after ptr by 5 integers not one that is the difference
7th Aug 2019, 7:10 PM
ABADA S
ABADA S - avatar
+ 3
Sai Ram it is not an array of pointers to integers why? in this case sizeof(ptr) equals to sizeof(any pointer) and sizeof(array of pointers) equals to sizeof(pointer)*n where n is the number of elements in the array so this is a single pointer to array not an array of pointers
7th Aug 2019, 10:24 PM
ABADA S
ABADA S - avatar
+ 1
its a pointer array. the difference between array and a pointer array is ->Normal Array stores variable values . ->Pointer array stores address of the variables.
7th Aug 2019, 10:06 PM
Sai Ram
+ 1
the precedence of bracket is first and associativity is left to right. so read the 1st bracket - (*ptr) which means it is a pointer then resolve 2nd bracket - [5] which means an array but you have got a pointer which means it is pointing to that array and finally int denotes the datatype of values stored in the array so ptr is a pointer to an array of 5 intergers
8th Aug 2019, 2:30 AM
Tarun
Tarun - avatar