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

Manmeet said:   1 decade 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.
(1)

Sufiyan said:   1 decade ago
Very good logic. Can you elaborate it?
(1)

Rama saranya said:   1 decade ago
-> is member off pointer operator as we use for accessing the structure variable.

Anukul said:   1 decade ago
"." is not actually referred to as a "dot" operator....it is an "direct selector".

"->" is an "indirect selector".

Mamta said:   1 decade ago
Actually address part of node represented by ->.
obj->pointer.

Appala prathyusha said:   1 decade ago
In the ex given by @Puja I have executed the program in online C compiler and executor. I got the output 0.

Kamlesh sharma said:   1 decade ago
Pointer definition: it can store the & of the other variable, so we are using pointer, using arrow "->", operator, ". ", dot operator are used in pointer.

Chandru said:   1 decade ago
Can we make use of ". " operator instead of "->" operator?

Puja said:   1 decade ago
->(spangles) = accesses the pointer variable that contains the address of another variable.

*(as-trick) = points the value of the variable declared.

&(ampersand) = points the address of the variable declared

enum(enumeration) = user-defined data type.

eg:

{
int a[10]={1,4,5);
printf("%d",a[3]);
}

output is 6.

Explanation: successive no.of 5 is 6.

JYOTI NAGPAL said:   1 decade ago
Yes, Its ans is D ex:

struct student
{
char name[20];
int rn;
}*s1;

If we access these data members in main then use,

//INPUT FROM KEYBOARD.

scanf("%s%d",s1->name,&s1->rn);

//DISPLAY THE OUTPUT.

printf("\nname= %s\troll no = %d",s1->name,s1->rn);


Post your comments here:

Your comments will be displayed after verification.