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 3 of 6.

Sidhesh said:   1 decade ago
@Ramchandra

Can we write the above code with the help of "." operator ?

Rakesh said:   1 decade ago
@sidesh:

In the above code instead of writing t->val=20;,

we can write
(*t).value=20; thats it..

Sanket joshi said:   1 decade ago
. operator use when we have to acces stru member with array.

-> when we have to acces with pointer.

Ranjansharan said:   1 decade ago
Can anybody say what is the actual difference, when we acces the member of struct by using "." operator & "->" operator ?

Siddhant said:   1 decade ago
For structure...we have to point to the struct variables's data member..that why..-> is used....in structure for pointer representation.

Siva said:   1 decade ago
Thanks kisan.

Pichuka said:   1 decade ago
Pichuka says thanks to kissan.

PAVAN SHARATH said:   1 decade ago
There are two ways of accessing a structure member through a structure variable.
Ex:- struct student
{
int a;
float b;
}s1;

Here, S1 is a structure variable and a,b are the members.
**IF S1 IS A NORMAL STRUCTURE VARIABLE ,THEN IT CAN DIRECTLY ACCESS THE MEMBERS OF STRUCTURE!! THIS PROCESS IS CALLED DIRECT ACCESSING!!
FOR THIS PURPOSE WE USE '.'(DOT) OPERATOR.
EXAMPLE::- S1.A,S1.B ETC.
** BUT IF THE STRUCTURE VARIABLE S1 IS OF POINTER TYPE!!
i.e *S1,
THEN THIS STORES THE ADDRESS OF THE VARIABLE AND HENCE CANNOT BE DIRECTLY ACCESSED!! IT NEEDS TO BE ACCESSED INDIRECTLY THROUGH THE ADDRESS PRESENT WITH IT. THIS IS CALLED INDIRECT ACCESSING!!
FOR THIS PURPOSE WE USE '->'(ARROW) OPERATOR.
EXAMPLE ::- S1->A,S1->B etc.


FINALLY CONCLUSION:::-
IF STRUCTURE VARIABLE IS NORMAL, THEN WE USE '.'(DOT OPERATOR) ALSO CALLED AS DIRECT ACCESS OPERATOR.
SIMILARLY IF VARIABLE IS POINTER TYPE, THEN WE USE '->'(ARROW OPERATOR) ALSO CALLED AS INDIRECT ACCESS OPERATOR!!!

Bharath said:   1 decade ago
Thanks kisan

Pramod shinde said:   1 decade ago
Finaly to normal structure variable we can use "."operator and to pointer type variable we can use "->"Operator.


Post your comments here:

Your comments will be displayed after verification.