C Structure

Contents

  • Structures and Unions
  • Giving values to members
  • Initializing structure
  • Functions and structures
  • Passing structure to elements to functions
  • Passing entire function to functions
  • Arrays of structure
  • Structure within a structure
  • Union.
Arrays are used to store large set of data and manipulate them but the disadvantage is that all the elements stored in an array are to be of the same data type.
If we need to use a collection of different data type items it is not possible using an array. When we require using a collection of different data items of different data types we can use a structure.
Example: 
	struct lib_books 
	{ 
		char title[20]; 
		char author[15]; 
		int pages; 
		float price; 
	}; 

Description

structure definition: 
general format: 
struct tag_name 
{ 
	data type member1; 
	data type member2; 
	… 
	… 
} 
the keyword struct declares a structure to holds the details of four fields namely title, author pages and price. These are members of the structures. Each member may belong to different or same data type.
The tag name can be used to define objects that have the tag names structure. The structure we just declared is not a variable by itself but a template for the structure.


Make Comments..!!


Oops!! No posts from user.