CS Behind the Curtain (CS195 2003S)
Primary:
[Front Door]
[Current]
[Glance]
-
[Blurb]
[Disabilities]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Walker/Fall 2001]
[SamR]
Summary: This lab reviews some of the basic types in C.
Citation: Many problems in this lab are closely based on problems from chapter 2 of
Kernighan, Brian W. and Ritchie, Dennis M. (1988). The C Programming Language, Second Edition: ANSI C. Englewood Cliffs, NJ: Prentice-Hall. ISBN: 0-13-1110362-8.
Contents:
Create a new directory for this laboratory. Initially, this directory should be empty.
Determine the minimum and maximum valid values for each of the following
types. Note that you will need to include limits.h and
refer to appropriate constants (such as UCHAR_MAX,
and SHRT_MIN).
char
unsigned char
short int
unsigned short int
int
unsigned int
long int
unsigned long int
Write a program that shows the effects of promotion, demotion, and other conversions between the various integral types.
Determine (using whatever technique you find best) whether our compiler
supports the signed long long int type introduced in C99.
If our compiler supports them, determine their range.
I would recommend that as part of your exploration, you type
info gcc and man gcc at the command line.
By looking at
/usr/lib/gcc-lib/i386-redhat-linux/2.96/include/float.h,
determine the valid ranges of floats, doubles, and long doubles. You
might also want to take notes on other interesting aspects of these
values.
By reflecting on the previous exercises, by writing a program that uses
sizeof, or both, determine the sizes of the various numeric
types (in bits or 8-bit bytes).
a. Create a program that declares an enumerated type, day,
that consists of the days of the week.
b. Add a main procedure that declares a variable,
today, of type day and assigns the
value MONDAY to it. (I am assuming that you have made
MONDAY one of the values in the enumerated type.) Your
main should also print out the value of today.
c. What do you expect to happen when you compile your program?
d. Confirm your answer experimentally. Correct any errors revealed in the compilation process.
e. Extend your program to assign the value 8 to today.
f. What do you expect to happen when you splint your program?
g. Verify your results experimentally.
h. What do you expect to happen when you compile your program?
i. Verify your results experimentally.
j. Reflect on what you've learned from this exercise.
Write a program or programs to answer each of the following questions:
a. What happens if you try to reuse the name of a value within a single enumerated type?
b. What happens if you try to reuse the name of a value across enumerated types?
c. What does the compiler report if you try to assign a value from one enumerated type to a variable of another enumerated type?
d. What does splint report if you try to assign a value from one enumerated type to a variable of another enumerated type?
e. What happens if you try to give two values the same name in a single enumerated type?
a. What do you expect the value of a to be after the
following series of commands?
b = 5; a = ++b - ++b;
b. What do you expect the value of a to be after the
following series of commands?
b = 5; a = b++ - b++;
c. Verify your answers experimentally using both our compiler and splint. Be prepared to discuss your expected and final answers.
Sorry, no notes yet.
Primary:
[Front Door]
[Current]
[Glance]
-
[Blurb]
[Disabilities]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Misc:
[Walker/Fall 2001]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Fri May 2 14:19:52 2003.
The source to the document was last modified on Mon Feb 10 16:07:46 2003.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS195/2003S/Labs/intro-types.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby