lecture9-feb8 - Announcements Lecture 9 Assignment 2 - due...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Announcements Lecture 9 • Assignment 2 - due Thursday - Q&A – Keep track of how many hours you spend on it – Keep track of how many logic errors you have to fix (not syntax errors) • Assignment 3 – out next week – due in 2 parts • Exam 1 – Fri. Feb 19 • Topics for today – typedef and sizeof ( ) operators – arrays 1D (Ch. 8) – Typical array algorithms Creating a Type Alias typedef lets you create an alias for a data type,e.g.: typedef float Dollars; typedef int Bool; • A common convention is to capitalize the first letter of a typedef alias name. • Once a type name has been defined, it can be used in the same way as any of the built-in type names: Dollars cash_in, cash_out, loan_balance; Bool flag; • Advantages of type definitions: – Can make programs more understandable. – Can make programs easier to modify. – Can make programs more portable. In C there is no easy way to enforce the additional constraints of the intended data type The sizeof () Operator • The sizeof ( ) operator can be used to determine how much memory a particular data type requires in bytes sizeof () returns an implementation-defined unsigned integer – What is sizeof (int) ? • it is best to cast the value returned by sizeof () to an unsigned long when printing it – Examples printf("Size of char: %lu\n", (unsigned long) sizeof(char) ); printf("Size of int: %lu\n", (unsigned long) sizeof(int) ); printf("Size of long int: %lu\n", (unsigned long) sizeof(long) ); sizeof() works with variables and expressions too: int i; printf("Size is: %lu\n", (unsigned long) sizeof(i + 1) ); Aggregates • In general, is there a better way to process whole collections (sets, groups,etc.) of similar values ? – For example, save all the chars in a message – Or save all the numbers being entered in a series – Or save all of your scores on the first exam 87 99 74 62 91 83 83 65 77 96 . . . Arrays - Definitions • An array is group (or collection) of multiple variables of the same data type. The values can be all: int, double, char, etc. – An array allows us to store and process all the values in the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/15/2010 for the course EE 16005 taught by Professor Krasner during the Spring '10 term at University of Texas at Austin.

Page1 / 3

lecture9-feb8 - Announcements Lecture 9 Assignment 2 - due...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online