Vidyalelo
C Programming · all questions

Structure and Union
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

190

Questions

3/10

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    struct student
    {
        int no;
        char name[20];
    };
    struct student s;
    no = 8;
    printf("%d", no);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    int x;
    char y;
};
int main()
{
    struct p p1[] = {1, 92, 3, 94, 5, 96};
    struct p *ptr1 = p1;
    int x = (sizeof(p1) / sizeof(struct p));
    printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
};
int main()
{
    struct point p = {1};
    struct point p1 = {1};
    if(p == p1)
        printf("equal\n");
    else
        printf("not equal\n");
}

Select an option to see the answer and solution.

Which of the following structure declaration doesn't require pass-by-reference?

Select an option to see the answer and solution.

How many bytes in memory taken by the following C structure?
#include <stdio.h>
struct test
{
    int k;
    char c;
};

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
    int x, y;
}k;
int main()
{
    struct p p = {1, 2};
    k k1 = p;
    printf("%d\n", k1.x);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char *a[3] = {"hello", "this"};
    printf("%s", a[1]);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
struct student fun(void)
{
    struct student s;
    s.name = "alan";
    return s;
}
void main()
{
    struct student m = fun();
    printf("%s", m.name);
}

Select an option to see the answer and solution.

What is the correct syntax to declare a function foo() which receives an array of structure in function?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *c;
};
void main()
{
    struct student *s;
    s->c = "hello";
    printf("%s", s->c);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    int x[2];
};
struct q
{
    int *x;
};
int main()
{
    struct p p1 = {1, 2};
    struct q *ptr1;
    ptr1->x = (struct q*)&p1.x;
    printf("%d\n", ptr1->x[1]);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
union p
{
    int x;
    char y;
}k = {.y = 97};
int main()
{
    printf("%d\n", k.y);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
void main()
{
    struct student s, m;
    s.name = "st";
    m = s;
    printf("%s%s", s.name, m.name);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    char *name;
};
struct student s[2], r[2];
void main()
{
    s[0].name = "alan";
    s[1] = s[0];
    r = s;
    printf("%s%s", r[0].name, r[1].name);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
};
void foo(struct point*);
int main()
{
    struct point p1[] = {1, 2, 3, 4, 5};
    foo(p1);
}
void foo(struct point p[])
{
    printf("%d %d\n", p->x, p[3].y);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char *a[3][3] = {{"hey", "hi", "hello"}, {"his", "her", "hell"}
    , {"hellos", "hi's", "hmm"}};
    printf("%s", a[1][1]);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
union u
{
    struct
    {
        unsigned char x : 2;
        unsigned int y : 2;
    }p;
    int x;
};
int main()
{
    union u u = {2};
    printf("%d\n", u.p.x);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    int k;
    char c;
};
int p = 10;
int main()
{
    struct p x;
    x.k = 10;
    printf("%d %d\n", x.k, p);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    char *name;
    struct p *next;
};
struct p *ptrary[10];
int main()
{
    struct p p;
    p.name = "xyz";
    p.next = NULL;
    ptrary[0] = &p;
    printf("%s\n", ptrary[0]->name);
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct p
{
    char *name;
    struct p *next;
};
struct p *ptrary[10];
int main()
{
    struct p p;
    p->name = "xyz";
    p->next = NULL;
    ptrary[0] = &p;
    printf("%s\n", p->name);
    return 0;
}

Select an option to see the answer and solution.