Dont copy the output

Discussion in 'C Programming' started by Ashokkumar, Feb 22, 2018.

  1. Ashokkumar

    Ashokkumar

    Joined:
    Feb 22, 2018
    Messages:
    1
    Likes Received:
    0
    Hi everyone,

    i have some details about struct and union oriented programs
    //gcc 5.4.0

    #include <stdio.h>

    typedef struct
    {
    char Name[10];
    int age;
    int salary;
    }person_t;

    person_t p;

    typedef union
    {
    char array[20];
    struct
    {
    person_t p;
    };
    }emp;
    emp e;
    unsigned char LoopData=0;

    /**********************************************************************/
    int main(void)
    {

    for(LoopData=0;LoopData<10;LoopData++)
    e.p.Name[LoopData]='A';
    e.p.age=30;
    e.p.salary=100;

    for(LoopData=0;LoopData<10;LoopData++)
    printf("%c",p.Name[LoopData]);
    printf("\n%d\n",p.age);
    printf("%d\n",p.salary);

    for(LoopData=0;LoopData<10;LoopData++)
    printf("%c",e.p.Name[LoopData]);
    printf("\n%d\n",e.p.age);
    printf("%d\n",e.p.salary);

    return 0;

    }


    output are:
    p.Name=0000000000
    p.age=0
    p.salary=0

    e.p.Name=AAAAAAAAAA
    e.p.age=30
    e.p.salary=100


    In this case e.p.name , e.p.age and e.p.salary values are reflected at p.name , p.age and p.salary.But our case dont reflect or dont copy the same output shows zero values.what happened the program?Pls guide me as soon as possible.
     
    Last edited: Feb 22, 2018
    Ashokkumar, Feb 22, 2018
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.