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

6/10

Page

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

For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?
struct temp
{
    int a : 13;
    int b : 8;
    int c : x;
}s;

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, q;
    p.name = "xyz";
    p.next = NULL;
    ptrary[0] = &p;
    strcpy(q.name, p.name);
    ptrary[1] = &q;
    printf("%s\n", ptrary[1]->name);
    return 0;
}

Select an option to see the answer and solution.

Which of the following cannot be a structure member?

Select an option to see the answer and solution.

Bit fields can only be declared as part of a structure.

Select an option to see the answer and solution.

Which of the following reduces the size of a structure?

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 n;
    struct student *s = &n;
    (*s).c = "hello";
    printf("%p\n%p\n", s, &n);
}

Select an option to see the answer and solution.

Which of the following uses structure?

Select an option to see the answer and solution.

What is the order for the following C declarations?
short a : 17;
int long y : 33;

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.p = {2};
    printf("%d\n", u.p.x);
}

Select an option to see the answer and solution.

Presence of loop in a linked list can be tested by . . . . . . . .

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;
};
int main()
{
    union p p, b;
    p.y = 60;
    b.x = 12;
    printf("%d\n", p.y);
}

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;
    float f;
};
int p = 10;
int main()
{
    struct p x = {1, 97};
    printf("%f %d\n", x.f, p);
}

Select an option to see the answer and solution.

Which of the following structure declaration will throw an error?

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;
    u.p.x = 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 student
{
    int no;
    char name[20];
}
void main()
{
    struct student s;
    s.no = 8;
    printf("hello");
}

Select an option to see the answer and solution.

Which of the following is false about typedef?

Select an option to see the answer and solution.

Which function is responsible for recording the name "s" and the replacement text "t" in a table?

Select an option to see the answer and solution.

The number of distinct nodes the following struct declaration can point to is . . . . . . . .
struct node
{
    struct node *left;
    struct node *centre;
    struct node *right;
};

Select an option to see the answer and solution.

In the following declaration of bit-fields, the constant-expression specifies . . . . . . . .
struct-declarator:
declarator
type-specifier declarator opt : constant-expression

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[2];
    printf("%d", sizeof(s));
}

Select an option to see the answer and solution.