clanguage07@gmail.com

clanguage07@gmail.com

Sunday, September 8, 2013

Pointer to structure in c programming


Pointer to structure: A pointer which is pointing to a structure is know as pointer to structure. 


Examples of pointers to structure:

What will be output if you will execute following code?


#include<stdio.h>

struct address{
char *name;
char street[10];
int pin;
}cus={"A.Kumar","H-2",456003},*p=&cus;

int main(){

printf("%s %s",p->name,(*p).street);


return 0;
}

Output: A.Kumar H-2
Explanation:

p is pointer to structure address.
-> and (*). Both are same thing. These operators are used to access data member of structure by using structure’s pointer.

No comments:

Post a Comment

GET MORE INFORMATION

http://ads.qadservice.com/t?id=c2168e05-8974-4816-872a-91936ff7379d&size=1024x768&drct=true