Home > C Programming > 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?
#include
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;
}
2. What will be the output of the following C code?
#include
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);
}
3. Which of the following return-type cannot be used for a function in C?
4. What will be the output of the following C code?
#include
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);
}
5. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?
(Assume: struct temp{int a;}s;)
6. Which of the following technique is faster for travelling in binary trees?
7. typedef int (*PFI)(char *, char *)creates ___________
8. 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;
}
9. 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);
}
10. What will be the output of the following C code?
#include
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}
11. Which of the following reduces the size of a structure?
12. Calculate the % of memory saved when bit-fields are used for the following C structure as compared to with-out use of bit-fields for the same structure? (Assuming size of int = 4)
struct temp
{
int a : 1;
int b : 2;
int c : 4;
int d : 4;
}s;
13. 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};
foo(&p1);
}
void foo(struct point *p)
{
printf("%d\n", *p.x++);
}
14. Which function is responsible for recording the name “s” and the replacement text “t” in a table?
15. What will be the output of the following C code?
#include
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(struct p));
printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
}
16. 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->x);
return 0;
}
17. What will be the output of the following C code?
#include
typedef struct student
{
char *a;
}stu;
void main()
{
stu s;
s.a = "hi";
printf("%s", s.a);
}s
18. What will be the output of the following C code?
#include
typedef struct p
{
int x, y;
};
int main()
{
p k1 = {1, 2};
printf("%d\n", k1.x);
}
19. Which of the following operation is illegal in structures?
20. How many bytes in memory taken by the following C structure?
#include
struct test
{
int k;
char c;
};
21. Which of the following is an incorrect syntax for pointer to structure?
(Assuming struct temp{int b;}*my_struct;)
22. What will be the output of the following C code?
#include
void main()
{
char *a[3] = {"hello", "this"};
printf("%s", a[1]);
}
23. What is typedef declaration?
24. What will be the output of the following C code?
#include
struct student
{
char *c;
};
void main()
{
struct student *s;
s->c = "hello";
printf("%s", s->c);
}
25. 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;
}