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

5/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>
struct point
{
    int x;
    int y;
};
void foo(struct point*);
int main()
{
    struct point p1 = {1, 2};
    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 p
{
    int x;
    char y;
    struct p *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.

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", s->c);
}

Select an option to see the answer and solution.

Comment on the output of the following C code.
#include <stdio.h>
struct temp
{
    int a;
    int b;
    int c;
};
main()
{
    struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}

Select an option to see the answer and solution.

Which of the following operation is illegal in structures?

Select an option to see the answer and solution.

The correct syntax to access the member of the ith structure in the array of structures is?
Assuming: struct temp
    {
        int b;
    }s[50];

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(ptr1));
    if (x == 1)
        printf("%d\n", ptr1->x);
    else
        printf("false\n");
}

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;
    struct student m;
    m.point = s;
    (m.point)->c = "hey";
    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>
union stu
{
    int ival;
    float fval;
};
void main()
{
    union stu r;
    r.ival = 5;
    printf("%d", r.ival);
}

Select an option to see the answer and solution.

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

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;
    struct student *m = &s;
    printf("%d", sizeof(student));
}

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 (*(*ptr)())[2] ptrfoo;
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.

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};
    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 student
{
    char *c;
    struct student point;
};
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
{
    unsigned int x : 1;
    unsigned int y : 1;
};
int main()
{
    struct p p;
    p.x = 1;
    p.y = 2;
    printf("%d\n", p.y);
}

Select an option to see the answer and solution.

Members of a union are accessed as . . . . . . . .

Select an option to see the answer and solution.

Which option should be selected to work the following C expression?
string p = "HELLO";

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

Select an option to see the answer and solution.

Which of the following data types are accepted while declaring bit-fields?

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();
    s.name = "turing";
    printf("%s", m.name);
}

Select an option to see the answer and solution.