Simple Example Programs for structure union and pointers

5
Here is the Simple Example Program for structure union and pointers

Program :
Code:
/*PROGRAM FOR UNION*/
#include <stdio.h>
#include <conio.h>
Union techno
{
    int id;
    char nm[50];
}tch;
void main()
{
    clrscr();
    printf("\n\t Enter developer id : ");
    scanf("%d", &tch.id);
    printf("\n\n\t Enter developer name : ");
    scanf("%s", tch.nm);
    printf("\n\n Developer ID : %d", tch.id);//Garbage
    printf("\n\n Developed By : %s", tch.nm);
    getch();
}

/*PROGRAM FOR STRUCTURE*/
#include <stdio.h>
#include <conio.h>
struct comp_info
{
    char nm[100];
    char addr[100];
}info;
void main()
{
    clrscr();
    printf("\n Enter Company Name : ");
    gets(info.nm);
    printf("\n Enter Address : ");
    gets(info.addr);
    printf("\n\n Company Name : %s",info.nm);
    printf("\n\n Address : %s",info.addr);
    getch();
}


/*PROGRAM USING POINTER*/
#include <stdio.h>
#include <conio.h>
void main()
{
    int a=10;
    int *ptr;
    clrscr();
    ptr = &a;
    printf("\n\t Value of a : %d", a);
    scanf("\n\n\t Value of pointer ptr : %d", *ptr);
    printf("\n\n\t Address of pointer ptr : %d", ptr);
    getch();
}

get the best... and reach the best...
Cool...
New&nbsp;Share your Study Materials with us :&nbsp;Click Here
thanks for the program bro...
Somesh - V+ Team Junior Moderator - Want for other subjects also? Arrow CLICK HERE

    Simple Example Programs for structure union and pointers