Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Arrays of structures

Node:Arrays of structures, Next:, Previous:Using structures, Up:struct



Arrays of structures

Just as arrays of basic types such as integers and floats are allowed in C, so are arrays of structures. An array of structures is declared in the usual way:

struct personal_data my_struct_array[100];

The members of the structures in the array are then accessed by statements such as the following:

The value of a member of a structure in an array can be assigned to another variable, or the value of a variable can be assigned to a member. For example, the following code assigns the number 1965 to the year_of_birth member of the fourth element of my_struct_array:

my_struct_array[3].year_of_birth = 1965;

(Like all other arrays in C, struct arrays start their numbering at zero.)

The following code assigns the value of the year_of_birth member of the fourth element of my_struct_array to the variable yob:

yob = my_struct_array[3].year_of_birth;

Finally, the following example assigns the values of all the members of the second element of my_struct_array, namely my_struct_array[1], to the third element, so my_struct_array[2] takes the overall value of my_struct_array[1].

my_struct_array[2] = my_struct_array[1];

 
 
  Published under free license. Design by Interspire