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

Kalidoss said:   2 decades ago
Pointers and Structures are used in the concept of Lined List, Stack, Queue ,etc.

In These Programs the address part or node is represented by the following
"obj->ptr"

Chinna said:   2 decades ago
Because specify the next address.

Sangeetha said:   1 decade ago
Very good keep it up (master brain).

Indhu said:   1 decade ago
I didn't understand.

Can you explain it clearly.
(1)

Sarvan said:   1 decade ago
@indhu

Pointer is just the address value, where the variable is stored. To get the address value we use "->" its just an representation. Hope you understand.
(1)

RaghuShri said:   1 decade ago
"." is used to access elements of a class via an object of class,eg-
class cls
{
public int a;
//some other work in this class
}
void main()
{
cls cls1=new cls();
cls1.a=20;//using "." operator here
}

and -> is used to access the elements of structures( it includes linked lists queues and stacks) eg- obj->element, you can guess the example at least rihht? take care, bye bye
(1)

Apurva Nigam said:   1 decade ago
@Raghushri:
We can access the elements of structures using "." also.
Eg:- obj.element

@ everybody:
Do we necessarily need to use "->" for a variable which is a pointer to a structure to access data members of the structure????
(2)

Maahi said:   1 decade ago
So finally which operator should be used? can any one tell?
(2)

Kisan said:   1 decade ago
. : used to access structure members with normal structure
variable.
-> : used to access structure members with pointer to structure

* : used to dereference a pointer.

& : used to obtain address of variable.
(2)

Apurva Nigam said:   1 decade ago
Thanks Kisan for properly explaining.


Post your comments here:

Your comments will be displayed after verification.