Home > General Studies (Hindi) > Quizzes > C Programming Practice Test: Structures, Unions and Bit-Fields
C Programming Practice Test: Structures, Unions and Bit-Fields
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “What will be the output of the following C code?”
Quiz questions on: Structures basics, functions, arrays of structures, pointer to structires, self referential structures, table lookup, typedefs, unions and bit fields. Structures: A structure is a user-defined data type that allows you to group together related data items. For example, you could create a structure to store information about a person, such as their name, age, and address. To declare a structure, you use the struct keyword followed by the name of the structure and a list of its members. Each member of a structure must have a type and a name. Once you have declared a... Show more
C Programming Practice Test: Structures, Unions and Bit-Fields
Time left 00:00
25 Questions

1. What will be the output of the following C code according to C99 standard?
#include
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97, .k = 1, 3};
printf("%f \n", x.f);
}
2. What will be the output of the following C code?
#include
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, p[3].y);
}
3. What will be the output of the following C code?
#include
struct p
{
unsigned int x : 7;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 110;
p.y = 2;
printf("%d\n", p.x);
}
4. What will be the output of the following C code?
#include
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->ptr->x);
return 0;
}
5. What will be the output of the following C code?
#include
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, (p + 2).y);
}
6. Which of the following return-type cannot be used for a function in C?
7. What happens when install(s, t) finds that the name being installed is already present in the table?
8. What will be the output of the following C code?
#include
struct temp
{
int a;
} s;
void func(struct temp s)
{
s.a = 10;
printf("%d\t", s.a);
}
main()
{
func(s);
printf("%d\t", s.a);
}
9. What will be the output of the following C code?
#include
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);
}
10. What will be the output of the following C code?
#include
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
printf("%s\n", ptrary[0]->name);
return 0;
}
11. What is the correct syntax to declare a function foo() which receives an array of structure in function?
12. 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;
13. What will be the output of the following C code?
#include
struct student
{
char *name;
};
struct student fun(void)
{
struct student s;
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s", m.name);
}
14. What will be the output of the following C code?
#include
struct student
{
char *name;
};
struct student s[2], r[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
r = s;
printf("%s%s", r[0].name, r[1].name);
}
15. Comment on the output of the following C code.
#include
struct temp
{
int a;
int b;
int c;
};
main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
16. What will be the output of the following C code?
#include
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student *m = &s;
printf("%d", sizeof(student));
}
17. What will be the output of the following C code?
#include
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);
}
18. What will be the output of the following C code?
#include
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 %d\n", p->x, ++p->x);
}
19. In what situation, install function returns NULL?
20. Which of the following are themselves a collection of different data types?
21. Which of the following is not possible regarding the structure variable?
22. Presence of code like “s.t.b = 10” indicates __________
23. Which of the following data types are accepted while declaring bit-fields?
24. Which of the following reduces the size of a structure?
25. What will be the output of the following C code?

#include
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");
}