Structures - Introduction to C Programming for Engineers - Slides | CSE A205, Study notes of Engineering

Material Type: Notes; Class: Introduction to C Programming for Engineers; Subject: Computer Systems Engineering ; University: University of Alaska - Anchorage; Term: Spring 2009;

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-kse
koofers-user-kse 🇺🇸

9 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A
Introduction to C Programming for Engineers
Lecture #19
Jeffrey Miller, Ph.D.
pf3
pf4
pf5

Partial preview of the text

Download Structures - Introduction to C Programming for Engineers - Slides | CSE A205 and more Study notes Engineering in PDF only on Docsity!

CSE294A

Introduction to C Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

Structures

Structures are used to group variables into a logicalarrangement for use by a programmer

Structures are constructed using objects of other types,such as

struct card

int face; char *suit;

When structures or structure member variables are passedto functions, they are passed by value

Structures can be passed by reference, or a pointer to thestructure can be passed (simulating a pass by reference)

typedef (cont.)

You can also create a structure with a typedef, as follows

typedef struct {

int face; char *suit;

} Card;

Note that if you use this approach, you can not createglobal variables in-line after the close curly brace

Enumerations

An enumeration is a set of integer enumeration constants represented byidentifiers

Values in an enum start with 0, so in the example below, JAN would beequivalent to 0, though this can be changed (as seen in months1)

enum months

{JAN,
FEB,
MAR};

enum months

{JANUARY
FEBRUARY,
MARCH};

void main()

char *mon[]

{“January”, “February”, “March”}; 6 enum months month; 7 for (month=JAN; month

MAR;

month++)

printf (“%s\n”, mon[month]); 9

Homework

Homework #7 is posted!