structure in c language: 15 flashcards
All 15 flashcards from this kit, free and with no sign-up.
1. What is a structure in C?
Show the answer
A user-defined data type that groups variables of different types under a single name.
2. Does defining a structure allocate memory?
Show the answer
No, defining a structure only describes the layout. Memory is allocated when a structure variable is declared.
3. Which operator is used to access a member of a structure variable?
Show the answer
The dot operator (`.`).
4. Which operator is used to access a member through a pointer to a structure?
Show the answer
The arrow operator (`->`).
5. What does `ptr->member` mean in terms of dereferencing?
Show the answer
It is equivalent to `(*ptr).member`.
6. How can you create an alias for a structure to simplify code?
Show the answer
Using `typedef`, e.g., `typedef struct Student Student;`.
7. Can structures be compared directly with `==`?
Show the answer
No, structures cannot be compared directly with `==`. You must compare member by member.
8. Is structure assignment (e.g., `s2 = s1;`) allowed in C?
Show the answer
Yes, structure assignment is allowed and copies all members.
9. Why might the size of a structure be larger than the sum of its members' sizes?
Show the answer
Because of padding bytes added by the compiler for memory alignment.
10. What is the foundation for implementing linked lists, stacks, and queues in C?
Show the answer
Structures, especially self-referential structures with pointers.
11. How do you initialize a structure variable at declaration?
Show the answer
Using braces with values in order, e.g., `struct Student s = {"Alice", 101, 95.5};`.
12. What is the advantage of passing a structure by pointer to a function?
Show the answer
It avoids copying the entire structure, which is more efficient for large structures and allows modification of the original.
13. What is the difference between `struct Student` and `Student` after `typedef struct Student Student;`?
Show the answer
They are the same type; `Student` is an alias for `struct Student`.
14. Can a structure contain an array as a member?
Show the answer
Yes, structures can contain arrays, other structures, and pointers.
15. How do you access a member of an array of structures?
Show the answer
Use array indexing followed by the dot operator, e.g., `students[0].roll`.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages