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

4/10

Page

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

In the following C code, we can access the 1st character of the string sval by using . . . . . .
#include <stdio.h>
struct
{
    char *name;
    union
    {
        char *sval;
    } u;
} symtab[10];
. .

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;
};
struct notpoint
{
    int x;
    int y;
};
int main()
{
    struct point p = {1};
    struct notpoint p1 = p;
    printf("%d\n", p1.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
{
    char *c;
};
void main()
{
    struct student m;
    struct student *s = &m;
    s->c = "hello";
    printf("%s", m.c);
}

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;
    struct student *point;
};
void main()
{
    struct student s;
    printf("%d", sizeof(s));
}

Select an option to see the answer and solution.

What is typedef declaration?

Select an option to see the answer and solution.

Which of the following is an incorrect syntax for pointer to structure?
(Assuming struct temp{int b;}*my_struct;)

Select an option to see the answer and solution.

The size of a union is determined by the size of the . . . . . . . .

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;
};
typedef struct p* q*;
int main()
{
    struct p p1[] = {1, 92, 3, 94, 5, 96};
    q ptr1 = p1;
    printf("%d\n", ptr1->x);
}

Select an option to see the answer and solution.

Which of the following is not possible regarding the structure variable?

Select an option to see the answer and solution.

What will be the output of the following C code? (Assuming size of int be 4)
#include <stdio.h>
struct temp
{
    int a;
    int b;
    int c;
} p[] = {0};
main()
{
    printf("%d", sizeof(p));
}

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 = {1, 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>
typedef struct p *q;
struct p
{
    int x;
    char y;
    q ptr;
};
int main()
{
    struct p p = {1, 2, &p};
    printf("%d\n", p.ptr->x);
    return 0;
}

Select an option to see the answer and solution.

Which operator connects the structure name to its member name?

Select an option to see the answer and solution.

Which of the following may create problem in the typedef program?

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};
    foo(p1);
}
void foo(struct point p[])
{
    printf("%d\n", 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 temp
{
    int a;
} s;
void change(struct temp);
main()
{
    s.a = 10;
    change(s);
    printf("%d\n", s.a);
}
void change(struct temp s)
{
    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 s[2];
void main()
{
    s[0].name = "alan";
    s[1] = s[0];
    printf("%s%s", s[0].name, s[1].name);
    s[1].name = "turing";
    printf("%s%s", s[0].name, s[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 p
{
    int x;
    char y;
};
void foo(struct p* );
int main()
{
    typedef struct p* q;
    struct p p1[] = {1, 92, 3, 94, 5, 96};
    foo(p1);
}
void foo(struct p* p1)
{
    q ptr1 = p1;
    printf("%d\n", ptr1->x);
}

Select an option to see the answer and solution.

Which algorithm is used for searching in the table?

Select an option to see the answer and solution.

What is the correct syntax to initialize bit-fields in an structure?

Select an option to see the answer and solution.