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.

Rohit Kumar said:   5 years ago
Here, convert all the options in postfix expression and read, the correct option will char *ptr[3];.

Vishal sanghani said:   5 years ago
char *ptr[3] is the right one.

Rajeshwar Reddy said:   8 years 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?

Naitik gupta said:   8 years ago
I agree the the pointer hold variable like these char(*ptr[3]);

Shatakshi Sharma said:   9 years 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.

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.

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.

Indu mounika said:   1 decade ago
ptr[3] shows an element of an aray.
So *ptr[3] is a valid pointer

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

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".


Post your comments here:

Your comments will be displayed after verification.