C Programming - Complicated Declarations - Discussion

1. 

Declare the following statement?
"An array of three pointers to chars".

[A].
char *ptr[3]();
[B].
char *ptr[3];
[C].
char (*ptr[3])();
[D].
char **ptr[3];

Answer: Option B

Explanation:

No answer description available for this question.

Dhiraj said: (Sep 22, 2010)  
What you have marked as answer is a pointer to an array of three character the correct answer will be char (*ptr)[3];

Bhavani said: (Dec 2, 2010)  
Yes (*ptr)[3] is correct.

Tamil said: (Dec 19, 2010)  
Yes. You are right. Ptr is the array which contains 3 character pointer.

Nagaraj said: (Dec 30, 2010)  
char *ptr[3]; It is an array wich consists of pointers.
int *(ptr[20]); It is the pointer to array of 10 elements

Nishu Nishant said: (Dec 31, 2010)  
Yes b option is correct *ptr[3]
*(ptr[3])is a pointer to array of 3 elements
where as *ptr[3] is an array consists of 3 pointers.
agreed with nagraj..

Raj said: (Jun 1, 2011)  
Option b is absolutely correct no discussion at all.

Richa Rao said: (Jul 10, 2011)  
It must be *ptr[2] as index start from 0th position.

Kavinder Singh said: (Sep 20, 2011)  
Yes b option is correct *ptr[3]
*(ptr[3])is a pointer to array of 3 elements
where as *ptr[3] is an array consists of 3 pointers.
agreed with nagraj and nishu

Raju said: (Feb 9, 2012)  
char *ptr[3] is correct. There is 3 characters are defined in pointers.

Ankita said: (Feb 26, 2012)  
In option (A) *ptr[3](); is a function means every pointer value is work as a function.
In optinc (c) (*ptr[3])(); is a complete pointer function.
In option (D) defines the pointer of pointer of array.
So,finally option(B) is correct,which gives "An array of three pointers to chars".

Gopi Krishnamraju said: (Mar 6, 2012)  
char *ptr[3]; ==>it means ptr is an array of three character pointers.

char (*ptr)[3] ==>it means ptr is a pointer to the array which consists 3 3 characters as its elements

Indu Mounika said: (May 19, 2012)  
ptr[3] shows an element of an aray.
So *ptr[3] is a valid pointer

Suman Pal said: (May 27, 2012)  
char *ptr[3] is right because it is a declaration of pointer of array, i.e., *(*(ptr+i)) where i is a character type of variable, store the address of char array type variable.

Sakthi Priya said: (Mar 19, 2013)  
Option b is the correct answer.

syntax for declaration "datatype_name variable_name;"

Here char is the datatype name.
*ptr[3]
* represent the pointer.
[3] represent the array.

Finally, char *ptr[3] represents "An array of three pointers to chars".

Option b is the correct answer for the given declaration.

Shatakshi Sharma said: (Sep 1, 2014)  
Option (b) signifies that we are having a pointer variable ptr.
[3] means 3 elements in array.

And char *ptr[3]means we are having a pointer that is pointing to an array which holds the character.

So option 2 is correct one.

Naitik Gupta said: (Sep 30, 2014)  
I agree the the pointer hold variable like these char(*ptr[3]);

Rajeshwar Reddy said: (Jan 5, 2015)  
char *ptr[3];

This means ptr is a array of size 3 (i.e. It contains 3 elements) , of type ptr (i.e. it contains 3 pointer elements) (i.e. it is an array of 3 pointers) , which is of type char?

Vishal Sanghani said: (Oct 3, 2017)  
char *ptr[3] is the right one.

Rohit Kumar said: (Aug 28, 2018)  
Here, convert all the options in postfix expression and read, the correct option will char *ptr[3];.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.