C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - General Questions (Q.No. 2)
2.
What do the following declaration signify?
int *ptr[30];
ptr is a pointer to an array of 30 integer pointers.
ptr is a array of 30 pointers to integers.
ptr is a array of 30 integer pointers.
ptr is a array 30 pointers.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
12 comments Page 1 of 2.

Omka akash said:   5 years ago
int *ptr[30]; (array of pointrs)=> ptr is array of 30 integer pointers.
Because square braces having more priority than * operator.

int (*ptr)[30];(pointer to an array)=> ptr is a pointer pointing to an array of 30 integers.
(1)

Tejas said:   6 years ago
A should be the answer. Because ptr is a pointer to an array of thirty integers.

Utkarsh said:   6 years ago
In declaration:

int p[20][30]; -> 20 elements each of which is an array of 30 ints.
is equivalent to int *p[30];

So, p is a pointer to an array of 30 ints.

Shilpa said:   1 decade ago
Let p is a pointer.
Declaration:

int a;
int *p=&a;//i.e p points to the content present in address of a...

So in the similar manner,*p[2] points to the address of some to variables say a ,b..

In the similar manner *p[30] points to 30 integer variables.

Shine said:   1 decade ago
B and C both are same I guess. Integer pointer and pointer to integer means same. Somebody please confirm.
(1)

Sona said:   1 decade ago
A should be the answer. Because ptr is a pointer to an array of three integer to pointer.

Prashant said:   1 decade ago
Yes. I think B and C both are same, and both answer are correct.
(1)

George said:   1 decade ago
[B]. ptr is a array of 30 pointers to integers.
[C]. ptr is a array of 30 integer pointers.

B and C are correct. pointers to integers and integer pointers are the same. For those brand new to coding and with weak english skills , this will be really confusing!
(1)

Vilas said:   1 decade ago
Yes.int *p;
then it means u declare p is a pointer to integer n when u declare
int ptr[30];
ptr is an array name to integer n here..
int *ptr[30];
ptr is a array of 30 pointers to integers.

Monika said:   1 decade ago
int *ptr[30];
it is an array of size 30 that contain integer pointer i.e.
array of 30 pointers to intger.


Post your comments here:

Your comments will be displayed after verification.