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?
Discussion:
60 comments Page 5 of 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);
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);
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.
*(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.
Chandru said:
1 decade ago
Can we make use of ". " operator instead of "->" operator?
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.
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.
Mamta said:
1 decade ago
Actually address part of node represented by ->.
obj->pointer.
obj->pointer.
Anukul said:
1 decade ago
"." is not actually referred to as a "dot" operator....it is an "direct selector".
"->" is an "indirect selector".
"->" is an "indirect selector".
Rama saranya said:
1 decade ago
-> is member off pointer operator as we use for accessing the structure variable.
Sufiyan said:
1 decade ago
Very good logic. Can you elaborate it?
(1)
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.
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)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers