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 2 of 6.
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
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)
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.
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)
Indhu said:
1 decade ago
I didn't understand.
Can you explain it clearly.
Can you explain it clearly.
(1)
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.
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);
Bhargavi said:
1 decade ago
enum is a one of the userdefined datatype,and it defines the list of keywords.
Ex:
enum rainbow
{
1.Red
2.Orange
3.Yellow
4.Green
5.Blue
6.Indigo
7.Violet
} ;
Ex:
enum rainbow
{
1.Red
2.Orange
3.Yellow
4.Green
5.Blue
6.Indigo
7.Violet
} ;
Nayan Shrimal said:
1 decade ago
Because it is a De-reference operator (->). So the data members can easily accessible.
Chandru said:
1 decade ago
Can we make use of ". " operator instead of "->" operator?
Haarika said:
1 decade ago
What is enum? in what situation we use it? can anybody help me out? please.
Ameena said:
1 decade ago
Pointer definition: it can store the & of the another variable, so we are using pointer, using arrow "->", operator, ". ", dot operator are used in pointer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers