C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - General Questions (Q.No. 1)
1.
Declare the following statement?
"An array of three pointers to chars".
char *ptr[3]();
char *ptr[3];
char (*ptr[3])();
char **ptr[3];
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
19 comments Page 1 of 2.

Sakthi Priya said:   1 decade ago
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.

Ankita said:   1 decade ago
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".

Shatakshi Sharma said:   1 decade ago
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.

Gopi Krishnamraju said:   1 decade ago
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

Rajeshwar Reddy said:   1 decade ago
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?

SUMAN PAL said:   1 decade ago
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.

Kavinder singh said:   1 decade ago
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

Nishu nishant said:   1 decade ago
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..

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

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


Post your comments here:

Your comments will be displayed after verification.