Skip to Main Content
C Programming: Visual Quickstart Guide
book

C Programming: Visual Quickstart Guide

by Larry Ullman, Marc Liyanage
October 2004
Beginner content levelBeginner
408 pages
9h 24m
English
Peachpit Press
Content preview from C Programming: Visual Quickstart Guide

Using Arrays of Structures

Structures, just like integers, floats, and characters, can be used in arrays. The syntax for creating one is just like you'd expect:

struct students {
   char name[30];
   float gpa;
};
struct students class[20];

To refer to an individual array element, you would of course refer to the array's index, like class[19]. To refer to an individual structural member of an individual array element, the syntax is

					array_name[index].field_name
class[10].gpa = 2.78;

In our next example, we create a list of student names and grades by taking input from the user and storing it in an array of structures.

To use arrays of structures

1.
Create a new file or project in your text editor or IDE.
2.
Type the standard beginning lines of code ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Intermediate C Programming

Intermediate C Programming

Yung-Hsiang Lu
Data Structures Using C

Data Structures Using C

Samir Kumar Bandyopadhyay, Kashi Nath Dey

Publisher Resources

ISBN: 0321287630Purchase book