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:
60 comments Page 5 of 6.

Nitin verma said:   1 decade ago
-> indicates direction toward's something and pointer is used for that in c.

Ramachandran said:   1 decade ago
I hope that given simple program clear your doubts.

#include<stdio.h>

struct node { //creating structure with a variable(val)
int val;
};

typedef struct node item;

void main() {
item *t; // declaring a struct type pointer variable

t=(item *)malloc(sizeof(item)); //allocating memory to struct
type pointer variable(t)
t->val=20; //accessing structure member(val) by using (t)
printf("value is %d",t->val);
}

Here item *t; is struct type pointer variable.So,By using struct type pointer variable(t),you can access the members of the structure(val) using the symbol ->

eg:- t->val=20;

Just copy and execute the program.

AukI said:   1 decade ago
Kan you give some example @Kisan, you provided information is very understandable but it would be lot better, if you can post some examples to your thoughts.

Sachincs033 said:   1 decade ago
Thanks buddies.

Hrudaya said:   1 decade ago
Thank u everyone for the explanation

Rekha said:   1 decade ago
Easily understandable good.

Wikiok said:   1 decade ago
(*myPointer).element <=equals=> myPointer->element

Vinoth said:   1 decade ago
Clear explanation Kisan

Vijaya said:   1 decade ago
When we create structure as a pointer, we have to access those structure members with structure object->structure variable.

Kiran said:   1 decade ago
Well said kisan.


Post your comments here:

Your comments will be displayed after verification.