Category: Structures in C

Structures in C

Unions in C

Unions in C

A union is a type that enables you to store different data types in the same memory space (but not simultaneously). A typical use is a table designed to hold a mixture of types...

Pointers to Structures

Pointers to Structures

The way we can have a pointer pointing to an int, or a pointer pointing to a char, similarly we can have a pointer pointing to a struct. Such pointers are known as ‘structure...

Passing Structure Variable to functions

Passing Structure Variable to functions

It can be immediately realized that to pass individual elements would become more tedious as the number of structure elements go on increasing. A better way would be to pass the entire structure variable...

Array of Structures

Array of Structures

Suppose we have to store data of 100 books we would be required to use 100 different structure variables from b1 to b100, which is definitely not very convenient. A better approach would be...

Accessing Structure Elements

Accessing Structure Elements

Having declared the structure type and the structure variables, let us see how the elements of the structure can be accessed.   In arrays we can access individual elements of an array using a...

Declaring a Structure

Declaring a Structure

In our example program, the following statement declares the structure type: This statement defines a new data type called struct book. Each variable of this data type will consist of a character variable called...

Structures Introduction

Structures Introduction

We have seen earlier how ordinary variables can hold one piece of information and how arrays can hold a number of pieces of information of the same data type. These two data types can...