C Programming - Arrays - Discussion

Discussion Forum : Arrays - General Questions (Q.No. 2)
2.
What does the following declaration mean?
int (*ptr)[10];
ptr is array of pointers to 10 integers
ptr is a pointer to an array of 10 integers
ptr is an array of 10 integers
ptr is an pointer to array
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
64 comments Page 3 of 7.

Yuvraj said:   1 decade ago
Hey, I m not getting difference between array of pointer and pointer of array. Can you please explain me?
(1)

Rahul kumar singh said:   1 decade ago
int (*ptr)[10] first we have to do the operation in bracket. So in bracket *ptr is there, notice the first variable name it is ptr then go right to the variable there is end bracket then move left of your variable indirection operator is there then again move towards right of ptr we get subscript so there it is array then left of ptr int is there. So ptr is a pointer to an array of 10 elements of type integer.
(1)

Sornalatha said:   1 decade ago
(*ptr) is a pointer. It point out the array of value [10]. So option B is correct.

Vikash kumar said:   1 decade ago
As we know ptr holds the address of variables, and *ptr means what is the value of variables on that address.

Sankar said:   1 decade ago
If any one clear about ptrs please explain clearly. Because I don't understanding anything belong to this.

Sanju said:   1 decade ago
Here ptr is the pointer it is represented by using *...! then the symbol [] shows that it is an array and 10 implies the size of that array.

Kumarachary said:   1 decade ago
@Vijayalaxmi is right.

We have to see the priority () have highest priority.

So int (*ptr)[] read it as pointer to array of integers.

If () is not there then int *ptr[] start with [] and it means array of pointers of type integers.
(1)

Tharun said:   1 decade ago
void main()
{
int (*d)[10];
d[0] = 7;
d[1]=10;
printf("%d\n",*d);
}

It should print 10 but compiler is showing error such as follows:

test.c:4:7: error: incompatible types when assigning to type \'int[10]\' from type \'int\'

Amr Gadallah said:   1 decade ago
char *ptr[10]; is an array of 10 pointers to characters.

char (*ptr)[10]; pointer to array of 10 characters.

Balu said:   1 decade ago
First it will read the variable part i.e, (*ptr) and after that it will go anti-clock wise direction then it will read array part([]). Then it will go to before (*ptr)[10]. There is nothing so it will leave.


Post your comments here:

Your comments will be displayed after verification.