🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
1. What is a structure in C?
Answer:
Explanation:
In C, a structure is a user-defined data type that allows grouping variables of different types under a single name.
2. How is a structure declared in C?
Answer:
Explanation:
Structures in C are declared using the 'struct' keyword followed by the structure name and its members.
3. Which of the following is the correct way to declare a structure in C?
Answer:
Explanation:
The correct syntax for declaring a structure in C is to use the 'struct' keyword, followed by the structure name and its members enclosed in braces.
4. How do you access a member of a structure in C?
Answer:
Explanation:
The dot operator (.) is used to access a member of a structure when using a structure variable.
5. How can a structure variable be initialized in C?
Answer:
Explanation:
A structure variable can be initialized by listing values in braces immediately after its declaration.
6. What is the purpose of a 'typedef' in relation to a structure in C?
Answer:
Explanation:
'typedef' is used to create an alias for a data type, which can simplify the syntax for declaring variables of complex types like structures.
7. How are structure members stored in memory?
Answer:
Explanation:
Structure members are stored in contiguous memory locations in the order in which they are declared.
8. Which of the following allows structures to be assigned to each other in C?
Answer:
Explanation:
In C, structures can be assigned to each other directly using the assignment operator.
9. How can you pass a structure to a function in C?
Answer:
Explanation:
Structures in C can be passed to functions either by value (copying the entire structure) or by reference (using pointers).
10. What is the output of the following C code?
struct Point { int x, y; };
struct Point p1 = {1, 2};
printf("%d, %d", p1.x, p1.y);
Answer:
Explanation:
The structure 'Point' is correctly initialized with x=1 and y=2, and these values are printed.
11. What is a nested structure in C?
Answer:
Explanation:
A nested structure in C is a structure that contains one or more other structures as its members.
12. Which keyword is used to access a member of a structure pointer in C?
Answer:
Explanation:
The arrow operator (->) is used to access members of a structure when you have a pointer to that structure.
13. How can the size of a structure be determined in C?
Answer:
Explanation:
The sizeof operator can be used to determine the size of a structure in bytes.
14. Can a structure in C contain a pointer to itself?
Answer:
Explanation:
A structure in C can contain a pointer to its own type, which is useful in creating data structures like linked lists.
15. What happens when a structure is passed to a function by value in C?
Answer:
Explanation:
When a structure is passed by value, a copy of the structure is created and passed to the function, so any modifications do not affect the original structure.
16. Is it possible to have an array of structures in C?
Answer:
Explanation:
In C, you can create an array of structures, allowing you to store multiple structures of the same type in an array format.
17. How do you initialize a pointer to a structure in C?
Answer:
Explanation:
A pointer to a structure is initialized by assigning it the address of a structure variable using the & operator.
18. Can a structure in C contain a member that is an array?
Answer:
Explanation:
Structures in C can contain array members, and the arrays can be of any type and size.
19. How can structures be compared in C?
Answer:
Explanation:
In C, structures are compared by manually comparing each of their members. The == operator cannot be used to compare structures directly.
20. What is a union in C?
Answer:
Explanation:
A union is similar to a structure in that it is a collection of variables, but in a union, all members share the same memory location.
Comments
Post a Comment
Leave Comment