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:


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’



Pointer to function
Pointer to array of function
Pointer to array of string
Pointer to structure
pointer to union
Multi level pointer
Pointer to array of pointer to string
Pointer to three dimentional array
Pointer to two dimensional array
Sorting of array using pointer
Pointer to array of array
Pointer to array of union
Pointer to array of structure
Pointer to array of character
Pointer to array of integer
C tutorial

2 comments:

dhabi said...

thats the way i wanted pointer defination...
it goes directly in ROM...

shwetha Acharya said...

Very nice explanation for pointers.. Thanks for ur effort!!