For All Human Beings.......

Tuesday, April 22, 2008

User Defined Data Type in C++ : Structure

Structures in C++

A structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Structures are declared in C++ using the following syntax:

struct structure_name
{
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
:
:
} object_names;

example :

struct
product
{
int weight;
float price;

} ;

product apple;
product banana, melon;

Subtopics Covered

  • Defining a Structure

  • Declaring structure variables

  • Accessing structure elements

  • Passing structure to Functions as value and reference argument/parameter

  • Function returning structure

  • Array of structures

  • passing an array of structure as an argument/ a parameter to a function

No comments: