C Programming - Complicated Declarations - Discussion

2. 

What do the following declaration signify?

int *ptr[30];

[A]. ptr is a pointer to an array of 30 integer pointers.
[B]. ptr is a array of 30 pointers to integers.
[C]. ptr is a array of 30 integer pointers.
[D]. ptr is a array 30 pointers.

Answer: Option B

Explanation:

No answer description available for this question.

Ankur said: (Nov 25, 2010)  
Answer c is correct.

Hitesh said: (Jan 21, 2011)  
No Ankur,the answer is only B coz when we declare
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: (Jan 26, 2011)  
int *ptr[30];
it is an array of size 30 that contain integer pointer i.e.
array of 30 pointers to intger.

Vilas said: (Oct 4, 2011)  
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.

George said: (Feb 15, 2012)  
[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!

Prashant said: (Apr 30, 2012)  
Yes. I think B and C both are same, and both answer are correct.

Sona said: (Jul 31, 2013)  
A should be the answer. Because ptr is a pointer to an array of three integer to pointer.

Shine said: (Aug 2, 2013)  
B and C both are same I guess. Integer pointer and pointer to integer means same. Somebody please confirm.

Shilpa said: (Dec 16, 2013)  
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.

Utkarsh said: (Jun 3, 2019)  
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.

Tejas said: (Jun 8, 2019)  
A should be the answer. Because ptr is a pointer to an array of thirty integers.

Omka Akash said: (Dec 22, 2020)  
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.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.