"Do not wait for leaders; do it alone, person to person."
- Mother Teresa
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?
[A].
.
[B].
&
[C].
*
[D].
->
Answer: Option A
Explanation:
No answer description available for this question.
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:
(Tue, Jul 20, 2010 08:33:48 PM)
Because specify the next address.
Sangeetha said:
(Thu, Dec 9, 2010 04:02:02 AM)
Very good keep it up (master brain).
Indhu said:
(Sat, Dec 18, 2010 12:45:23 AM)
I didn't understand.
Can you explain it clearly.
Sarvan said:
(Sat, Dec 18, 2010 09:21:24 AM)
@indhu
pointer is just the address value, where the variable is stored. To get the address value we use "->" its just an representation. hope u understand.
Raghushri said:
(Mon, Dec 27, 2010 07:41:10 AM)
"." 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
Apurva Nigam said:
(Wed, Jan 5, 2011 10:45:23 AM)
@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????
Maahi said:
(Sun, Jan 9, 2011 11:23:15 AM)
So finally which operator should be used? can any one tell?
Kisan said:
(Tue, Jan 11, 2011 02:25:43 AM)
. : 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.
Apurva Nigam said:
(Fri, Jan 21, 2011 09:02:57 AM)
Thanks Kisan for properly explaining.
Kiran said:
(Wed, Feb 23, 2011 12:34:52 PM)
Well said kisan.
Vijaya said:
(Thu, Mar 3, 2011 02:32:29 AM)
When we create structure as a pointer, we have to access those structure members with structure object->structure variable.
Kan you give some example @Kisan, you provided information is very understandable but it would be lot better, if you can post some examples to your thoughts.
Ramachandran said:
(Fri, Aug 19, 2011 12:34:05 AM)
I hope that given simple program clear your doubts.
#include<stdio.h>
struct node { //creating structure with a variable(val)
int val;
};
typedef struct node item;
void main() {
item *t; // declaring a struct type pointer variable
t=(item *)malloc(sizeof(item)); //allocating memory to struct
type pointer variable(t)
t->val=20; //accessing structure member(val) by using (t)
printf("value is %d",t->val);
}
Here item *t; is struct type pointer variable.So,By using struct type pointer variable(t),you can access the members of the structure(val) using the symbol ->
eg:- t->val=20;
Just copy and execute the program.
Nitin Verma said:
(Tue, Sep 6, 2011 01:38:45 PM)
-> indicates direction toward's something and pointer is used for that in c.
Sidhesh said:
(Fri, Sep 9, 2011 11:38:44 PM)
@Ramchandra
Can we write the above code with the help of "." operator ?
Rakesh said:
(Thu, Oct 13, 2011 03:05:31 PM)
@sidesh:
In the above code instead of writing t->val=20;,
we can write
(*t).value=20; thats it..
Sanket Joshi said:
(Wed, Oct 19, 2011 01:03:11 PM)
. operator use when we have to acces stru member with array.
-> when we have to acces with pointer.
Ranjansharan said:
(Wed, Oct 19, 2011 10:32:34 PM)
Can anybody say what is the actual difference, when we acces the member of struct by using "." operator & "->" operator ?
Siddhant said:
(Tue, Nov 1, 2011 07:56:18 PM)
For structure...we have to point to the struct variables's data member..that why..-> is used....in structure for pointer representation.
Siva said:
(Fri, Dec 2, 2011 10:38:31 AM)
Thanks kisan.
Pichuka said:
(Fri, Dec 2, 2011 03:46:21 PM)
Pichuka says thanks to kissan.
Pavan Sharath said:
(Tue, Dec 6, 2011 08:19:27 PM)
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:
(Sat, Jan 28, 2012 06:37:08 AM)
Thanks kisan
Pramod Shinde said:
(Sat, Feb 4, 2012 02:00:06 PM)
Finaly to normal structure variable we can use "."operator and to pointer type variable we can use "->"Operator.