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

2/10

Page

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

Which keyword is used to access a member of a nested structure in C?

Select an option to see the answer and solution.

What is the main advantage of using a union in C?

Select an option to see the answer and solution.

What is the size of an empty structure in C?

Select an option to see the answer and solution.

In C, can you compare two structures using the equality operator (==)?

Select an option to see the answer and solution.

What is the primary use of a union in a C program?

Select an option to see the answer and solution.

How do you declare an array of structures in C?

Select an option to see the answer and solution.

Which of the following is not a valid type for a structure member in C?

Select an option to see the answer and solution.

In C, can you have a structure as a member of itself (a recursive structure)?

Select an option to see the answer and solution.

What is the purpose of the offsetof macro in C?

Select an option to see the answer and solution.

Which keyword is used to create a new name for an existing data type in C?

Select an option to see the answer and solution.

Find the output of the following program:
void main()
{
   struct xx
   {
      int x=3;
      char name[]="hello";
   };
   struct xx *s;
   printf("%d", s->x);
   printf("%s", s->name);
}

Select an option to see the answer and solution.

Consider the following code.
struct account{
   int acno;
}svar, *pv = &svar;

then the acno can be accessed by

Select an option to see the answer and solution.

Consider the following declarations:
union id
{
   char color;
   int size;
};
struct{
   char country;
   int date;
   union id id;
}flag;

To assign a color to a flag, the correct statement would be

Select an option to see the answer and solution.

For the following structure declaration, find the correct statement.
struct person{
   char name[20];
   int  age;
   struct person lady;
};

Select an option to see the answer and solution.

The restriction with union is

Select an option to see the answer and solution.

How many union members can be initialized?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Can the following C code be compiled successfully?
#include <stdio.h>
struct p
{
    int k;
    char c;
    float f;
};
int main()
{
    struct p x = {.c = 97, .f = 3, .k = 1};
    printf("%f\n", x.f);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int *(*(x()))[2];
typedef int **(*ptrfoo)())[2];
int main()
{
    ptrfoo ptr1;
    ptr1 = x;
    ptr1();
    return 0;
}
int *(*(x()))[2]
{
    int (*ary)[2] = malloc(sizeof * ary);
    return &ary;
}

Select an option to see the answer and solution.

Which of the following share a similarity in syntax?
1. Union, 2. Structure, 3. Arrays and 4. Pointers

Select an option to see the answer and solution.