IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Pointers - Discussion

@ : Home > C Programming > Pointers > General Questions - Discussion

Read more:

"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.


Kalidoss said: (Sun, Jul 11, 2010 12:27:51 AM)    
 
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.

Vinoth said: (Fri, Mar 18, 2011 06:08:01 AM)    
 
Clear explanation Kisan

Wikiok said: (Sun, Apr 10, 2011 02:28:21 PM)    
 
(*myPointer).element <=equals=> myPointer->element

Rekha said: (Fri, May 20, 2011 06:45:35 AM)    
 
Easily understandable good.

Hrudaya said: (Sun, Jun 5, 2011 03:30:29 AM)    
 
Thank u everyone for the explanation

Sachincs033 said: (Tue, Jun 7, 2011 03:29:12 AM)    
 
Thanks buddies.

Auki said: (Sun, Jul 17, 2011 10:53:59 PM)    
 
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.

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!