To holds the details of four fields namely title, author pages and price,the keyword struct declares a structure. These are the members of the structures. Each member may belong to same or different data type. The tag name can be used to define the objects that have the tag names structure. The structure we just declared is not a variable by itself but a template for the structure.
We can declare the structure variables using the tag name any where in the program. For example the statement,
struct lib_books book1,book2,book3;
declares the book1,book2,book3 as variables of type struct lib_books each declaration has four elements of the structure lib_books. The complete structure declaration might look like this
The complete structure declaration might look like this
/* Example program for using a structure*/
#include< stdio.h >
printf("Enter the student information");
printf("Now Enter the student id_no");
printf(“Enter the name of the student”);
printf(“Enter the address of the student”);
printf(“Enter the cmbination of the student”);
printf(Enter the age of the student”);
printf(“Age of student=%d\n”,newstudent.age);
However the members that we compose a union all share the same storage area within the computers
memory where as each member within a structure is assigned its own unique storage area.
Thus unions are used to observe memory. They are useful for the application involving multiple members.
Where values need not be assigned to all the members at any time.
Unions like structure contain members whose individual data types may differ from one another also.
Like structures union can be declared using the keyword union as follows:
Last example will create a rectangle with rounded corner:
The notation for accessing a union member that is nested inside a structure remains the same as for the nested structure.In effect,a union creates a storage location that can be used by one of its members at a time. When a different number is assigned to a new value the new value supercedes the previous members value. Unions may be used in all the places where a structure is allowed.
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Structures in c,
data structures in c,
structures in c++,
structs in c,
structures in c#,
array of structures in c,
data structures and algorithm analysis in c,
typedef in c,
sizeof in c,
enum in c,
extern in c,
operator in c,
null in c,
delete in c,
array in c