Techiio-author
Started by Anik AdhikaryMay 7, 2022

Open
can anyone tell me why i am not getting name it's show 'b' instead of Anik ?

4 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 4 VIEWES SHARE
#include <stdio.h>
#include <string.h>
union Student{
    char name[10];
    struct {
        int marks;
        char subject[10];
    }score;
};
int main()
{    
    union Student stu;
    strcpy(stu.name, "Anik");
    stu.score.marks = 98;
    strcpy(stu.score.subject, "Math");
    printf("Name: %s\n", stu.name);
    printf("Subject:%s\n", stu.score.subject);
    printf("Marks: %d\n", stu.score.marks);
    return 0;
}

1 Replies

Techiio-commentatorSidhdarth Basu replied 6 days ago0 likes0 dislikes
#include <stdio.h>
#include <string.h>
union Student{
    struct {
        char name[10];
        int marks;
        char subject[10];
    }score;
};
int main()
{    
    union Student stu;
    strcpy(stu.score.name, "Anik");
    stu.score.marks = 98;
    strcpy(stu.score.subject, "Math");
    printf("Name:%s\n", stu.score.name);
    printf("Subject:%s\n", stu.score.subject);
    printf("Marks: %d\n", stu.score.marks);
    return 0;
}

I underline your mistakes .

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance