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 1 of 7.

Prashanth said:   2 years ago
int ptr[10] means ptr is an array of 10 elements whose datatype is int.
int a;
int *ptr=a; means ptr is a pointer pointing to a which is an integer type.

(int *) ptr[10] means ptr is an array of 10 elements whose datatype is int and they all are pointers.

in (*ptr)[10] means ptr is a pointer which is pointing to 10 elements which are of int datatype.
(11)

Sirish said:   2 years ago
Here, we can observe there is no comma operator ( (*ptr) , [10]) so, we can identify what's the array name, because the array name must be declared. So, *ptr=a, then the array becomes a[10], 10 elements are there in the array "a".
(6)

Dinesh Kumar Nayak said:   4 years ago
Agree, B is the right answer.
(3)

Teja said:   5 years ago
ptr is a pointer which points an array.
(2)

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)

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)

Abhishek prajapati said:   6 years ago
As we write ' int a[10] ' then we call it:- a is an array of 10 integer type elements.

Like that we can say in " int (*ptr)[10] "ptr (due to * ptr is pointer variable) is a pointer to an array of 10 integer type elements.
(1)

Siva said:   6 years ago
ptr is a pointer variable that can store an array of integer values(i.e. 10 integer values).
(1)

Ashik said:   5 years ago
Please explain in detail.
(1)


Post your comments here:

Your comments will be displayed after verification.