Structures in C Programming (2026 Guide) – Syntax, Types, Examples & Practice Programs for Beginners

Before learning Structures in C Programming, it is highly recommended to understand these important topics:

👉 Variables In C
👉 Functions In C
👉 Arrays In C
👉 Pointers In C
👉 Strings In C

Why?

Because structures in C are used to combine different types of data into one unit.

Variables store single values.
Arrays store multiple values of the same type.
Strings store characters.
Structures store multiple values of different data types together.

Important: Structures help organize related data efficiently in real-world applications.

What is a Structure in C?

A structure in C is a user-defined data type that allows you to store multiple types of data under one name.

Example:

struct Student
{
    int roll;
    char name[20];
    float marks;
};

Here:

  • Student → structure name
  • roll → integer member
  • name → string member
  • marks → float member

Why Do We Need Structures in C?

In real-world programming, we often work with related data.

  • Student details
  • Employee records
  • Bank accounts
  • Hospital systems
  • Product information

Structures help us:

  • ✔ Organize data efficiently
  • ✔ Improve readability
  • ✔ Handle complex data easily
  • ✔ Build real-world applications

Syntax of Structure in C

struct structure_name
{
    data_type member1;
    data_type member2;
};

Creating Structure Variables

struct Student s1;
Now s1 becomes a structure variable.

Accessing Structure Members

The dot (.) operator is used to access members.

s1.roll = 1;
strcpy(s1.name, "John");
s1.marks = 95.5;

Complete Structure Example

#include <stdio.h>
#include <string.h>

struct Student
{
    int roll;
    char name[20];
    float marks;
};

int main()
{
    struct Student s1;

    s1.roll = 1;
    strcpy(s1.name, "John");
    s1.marks = 90.5;

    printf("Roll: %d\n", s1.roll);
    printf("Name: %s\n", s1.name);
    printf("Marks: %.2f\n", s1.marks);

    return 0;
}
Output:
Roll: 1
Name: John
Marks: 90.50

Array of Structures

struct Student s[3];

Used for:

  • ✔ Student databases
  • ✔ Employee records
  • ✔ Product lists

Structure Initialization

struct Student s1 = {1, "John", 95.5};

Nested Structures

struct Address
{
    char city[20];
};

struct Student
{
    int roll;
    struct Address addr;
};

Pointer to Structure

struct Student s1;
struct Student *ptr = &s1;

ptr->roll = 10;
The -> operator is used with structure pointers.

typedef with Structures

typedef struct
{
    int id;
    char name[20];
} Employee;

Now you can write:

Employee e1;

Difference Between Array and Structure

Array Structure
Stores same data types Stores different data types
Uses indexes Uses member names
Example: int arr[5] Example: struct Student

Advantages of Structures

  • ✔ Store different data types together
  • ✔ Organize complex data
  • ✔ Improve code readability
  • ✔ Useful in real-world applications
  • ✔ Supports arrays and pointers

Limitations of Structures

  • Slightly complex for beginners
  • Memory usage can increase
  • Structures cannot perform operations directly

Real-World Uses of Structures

  • Student management systems
  • Employee databases
  • Hospital software
  • Banking systems
  • Game development
  • Operating systems

Practice Programs on Structures

🟢 Easy Level:

  • Program to store student details
  • Program to display employee information

🟡 Medium Level:

  • Program using array of structures
  • Program to calculate student average

🔴 Advanced Level:

  • Program using nested structures
  • Program using structure pointers
  • Program using typedef structures

Structures and Functions in C

void display(struct Student s)
{
    printf("%d", s.roll);
}
Structures can be passed to functions for better program organization.

Structures vs Unions in C

Structure Union
Separate memory for members Shared memory
Larger memory usage Smaller memory usage
All values stored simultaneously One value stored at a time

Conclusion

✔ Combine related data
✔ Build real-world applications
✔ Organize programs efficiently
✔ Manage complex information easily

FAQ – Structures in C

Q1: What is a structure in C?

A structure is a user-defined data type used to group different data types together.

Q2: Which operator is used to access structure members?

The dot (.) operator.

Q3: Which operator is used with structure pointers?

The arrow (->) operator.

Q4: Can structures contain arrays?

Yes.

Q5: Why are structures important in C?

Structures help organize and manage complex real-world data efficiently.


Keep practicing and keep coding 💛

Related Posts:

Comments

Popular posts from this blog