Difference between Structure and Union in C

Question: What is the Difference between Structure and Union in C? Answer: Unions and structures are declared alike but they work differently. Let’s discuss differences Structure and Union in C. Consider the declarations below, typedef union { int a; float b; char c; } A_union;   typedef struct { int a; float b; char c; … Read more

advertisement

What is Union in C Language?

This C Tutorial explains Union and its initialization in C Language with examples. A union is altogether different from structure but declared like structure. For example, union { int x; float y; char c; } val; Notice that in above declaration, union is declared just like structure but amount of memory allocated to union is … Read more

advertisement

Bit Fields in C Programming with Examples

This C Tutorial explains Bit Fields in C Language with examples. Bit fields in C are a type of data structure used to store data in a series of bits. Structures in C are capable of implementing bit fields. Bit fields are declared as other structure declarations with difference that member’s are fields of one … Read more

advertisement

How to Pass or Return a Structure from a Function in C

Question: Can a Function in C Obtain Structures as Formal Arguments and Return Structures as Return Values? Answer: Of course! A structure is a scalar variable like any other variable and therefore can be used wherever a variable is used. As we know that passing an argument by value in C requires copy of argument … Read more

advertisement

Structure Boundary Alignment in C

This C Tutorial explains boundary alignment for Structures with examples. Actually, on certain machines, type ‘int’ is allocated storage which begins at address divisible by 4. Such type ‘int’ is called stringent data type. Because of this restriction structures begin at address required by boundary aligned of the stringent data type. Compiler is forbidden to … Read more

advertisement

Difference between Dot and Arrow Operators in C

Question: What is Difference in Accessing Structure Members Using Dot ‘.’ and Arrow Operator ‘->’ in C Language? Answer: We know that we can access structure members in two different ways, one using dot ‘.’ operator and other using arrow ‘->’ operator. Let’s differentiate between two, consider an example, /* dot_access.c — program accesses structure … Read more

advertisement

Nested Structure in C with Examples

This C Tutorial explains Nested structure in C with examples and How can we access them. What is Nested Structure in C? Nested structure is a structure whose member is itself a structure. Let’s see the Nested structure declaration below, struct A { int a; float b; };   struct B { int c; float … Read more

advertisement

Difference between Pointer Arithmetic on Structures and Pointer Arithmetic on Arrays in C

Question: How Pointer Arithmetic on Structures Differs from Pointer Arithmetic on Arrays in C Programming? Answer: This can better be understood by considering an example, struct A { int a; float b; char c[3]; };   int main(void) { struct A x = {10, 23.33, "hi"}; struct A *p2x = &x; /* ‘p2x’ is pointing … Read more

advertisement

Structure in C Programming with Examples

This tutorial explains Structures in C Programming with examples. Structures are one of the most important data types in C. They allow you to store data in an organized way, and they provide an easy way to access that data. How to create a structure in C? There are two ways to create a structure … Read more

advertisement

Mutually Dependent Structures in C

Question: What are Mutually Dependent Structures in C? Answer: Two structures, for example, say A and B, are called mutually dependent if one of members of each refers to other structure. For example, struct A { struct B b; int value; };   struct B { struct A a; float wool; }; Can these structure … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.