C Programming - Pointers - Discussion

Discussion Forum : Pointers - General Questions (Q.No. 5)
5.
If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
.
&
*
->
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
59 comments Page 1 of 6.

Deepak said:   4 years ago
@All.

The eg Syntax is;

struct node
{
int data;
};
main(){
struct node p,*a;
P.data=10;
a=&p;
printf(" %d",a->data);
}

And Output is 10.
(4)

Swapnika said:   4 years ago
Dot (.) operator also used in pointers.
(3)

Priya said:   8 years ago
I did not understand this question. Please help me to get this.
(2)

Ashish said:   8 years ago
I think the answer given to the question is wrong.

We can use(*p).x instead of using ->.
(2)

Dhairya said:   8 years ago
Pointer is a collection of data;& operator access a memory in & by Code block.

Sumit said:   8 years ago
We can use either (*p).x or p->x where x is the member of the structure.

Sayli said:   8 years ago
Good explanation. Thanks @Kisan.

Jatin said:   9 years ago
Here we can use arrow operator to access structure members without creating structure variable that's why we used -> (arrow) operator.

Nayan Shrimal said:   9 years ago
Because it is a De-reference operator (->). So the data members can easily accessible.

Manmeet said:   9 years ago
When ever we want to fetch the value out of a pointer variable which is store in a structure.

We always use -> (arrow) pointer.

On the other hand if in a structure we have a simple variable of any data type we will use .(dot) operator to fetch the value from a variable.


Post your comments here:

Your comments will be displayed after verification.