Monday

Pointer to union in c programming


Pointer to union 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:

1.What will be output if you will execute following code?

            #include<stdio.h>

             union address{

             char *name;

             char street[10];

             int pin;

          };

             int main(){

             union address emp,*p;

             emp.name="ja\0pan";

             p=&emp;

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

           return 0;

       }
Output: ja ja

Explanation:

p is pointer to union address.

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

%s is used to print the string up to null character i.e. ‘\0

Kindly Bookmark this Post using your favorite Bookmarking service:
Technorati Digg This Stumble Stumble Facebook Twitter
YOUR ADSENSE CODE GOES HERE

0 comments:

Post a Comment

Dont Forget for Commets

 

| C programing tutorials © 2009. All Rights Reserved | Template Style by My Blogger Tricks .com | Design by Brian Gardner | Back To Top |