Structure and Union MCQs

190 questionsC-ProgramPage 19 of 22

Practice free Structure and Union multiple-choice questions with instant answer feedback and step-by-step solutions. Click an option to check yourself, reveal the full explanation, and work through all 190 questions — no login required.

Question 163hard
What will be the output of the following C code?
#include <stdio.h>
struct point
{
    int x;
    int y;
} p[] = {1, 2, 3, 4, 5};
void foo(struct point*);
int main()
{
    foo(p);
}
void foo(struct point p[])
{
    printf("%d %d\n", p->x, p[2].y);
}
Question 164medium
Which of the following is not possible under any scenario?
Question 165hard
Calculate the % of memory saved when bit-fields are used for the following C structure as compared to with-out use of bit-fields for the same structure? (Assuming size of int = 4)
struct temp
{
    int a : 1;
    int b : 2;
    int c : 4;
    int d : 4;
}s;
Advertisement
Question 166hard
What will be the output of the following C code?
#include <stdio.h>
typedef struct student
{
    char *a;
}stu;
void main()
{
    struct stu s;
    s.a = "hi";
    printf("%s", s.a);
}
Question 167hard
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;
    s.no = 8;
    printf("%d", s.no);
}
Question 168easy
Which of the following statement is true?
Advertisement
Question 169hard
What will be the output of the following C code?
#include <stdio.h>
union u
{
    struct p
    {
        unsigned char x : 2;
        unsigned int y : 2;
    };
    int x;
};
int main()
{
    union u u;
    u.p.x = 2;
    printf("%d\n", u.p.x);
}
Question 170medium
Which of the given option is the correct method for initialization?
typedef char *string;
Question 171hard
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) / 3);
    if (x == sizeof(int) + sizeof(char))
        printf("%d\n", ptr1->x);
    else
        printf("falsen");
}