








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Hollingsworth; Class: INTRO TO LOW-LEVEL PROG; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









l^
l^
l^
l^
l^
l^
int a;char b;float c; } x; •^
Declares a single variable x with 3 fields
l^
Often useful to use typedef and struct together:typedef struct {
int a;char b;float c; } Simple; l^
Declarations then look like:Simple x;Simple y[20], z; l^
Header Files–
If structure used by more than one file, put it in a header file.– If you want programmers who will be using your implementation to seethis struct, put it in the header file.– Use
#include
to include definition in each file where used.
l^
int a;char b;float c; } x, y[10]; l^
l^
l^
type
variablename:size;
l^
/* from project #1 */
unsigned int opCode:4;unsigned int r1:4;unsigned int r2:4;unsigned int r3:4;unsigned int address:16;} instruction;
typedef struct { char productName[200];int quantity;float unitPrice; } Transaction;void printReceipt( Transaction trans){
printf("product = %s\n", trans.productName);printf("
quanity = %d\n", trans.quanity);
printf("
price = %f\n", trans.unitPrice);
} int main(void){Transaction foo;printReceipt(foo); l^
typedef struct { char productName[200];int quantity;float unitPrice; } Transaction;void initReceipt(Transaction *trans){
trans->productName[0] = ‘\0’;trans->quanity = 0;trans->unitPrice = 12.50; } int main(void){Transaction foo;initReceipt(&foo);
Indicates pointer type variable
Indicates pass the reference (the address)
l^
Syntax is similar to structs l^
Rather than storing each field, only stores
one
of the fields
-^
Handy when need to stores different things based on criteria
l^
Syntax:–
union [tag] { member-list } [variable-list];– again, the things in [ ] are optional– the { } and ; are required l^
Examples:union {
float f;int i; } objname;objname.f = 3.14159;
l^
l^
0x000x040x080x0c0x100x
struct { int a;char b;int c; } x; x = { 3, 'a', 10 };
3 0 0 0
0x (^0) (^0) (^0)
? ?^
?
0xA
l^