CSC161 2011S Imperative Problem Solving
[Skip to Body]
Primary:
[Front Door]
[Schedule]
[Piazzza]
-
[Academic Honesty]
[Instructions]
Current:
[Current Outline]
[Current EBoard]
-
[Current Assignment]
[Current Lab]
[Current Reading]
Groupings:
[Assignments]
[Documents]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
[Reference]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
[CSC161 2010F (Rebelsky)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
Summary: We explore basics of types in C.
Prerequisites: Familiarity with basic Linux commands. Ability to use an editor. Ability to compile C files.
a. Log in to your MathLAN workstation. (Of course, you've probably already done that if you're reading this laboratory.)
b. Open a terminal window into which you can type commands.
c. Create a directory for this lab. (I'd suggest something like
~/Courses/CSC161/MoreTypes/, but it's up to you.)
d. In that directory, create a file called Makefile that
contains the following line.
CFLAGS=-Wall
Determine experimentally, what happens when
For example, to explore the assignment of a long to a short, you might write
long l;
short s;
...
l = SHRT_MAX + 5;
s = l;
printf ("Long: %ld\n", l);
printf ("Short: %d\n", s);
Consider the following code:
enum values { ALPHA, BETA, GAMMA };
int
main ()
{
int i;
enum values v;
i = BETA;
v = 23;
}
a. What do you expect the compiler to do if you attempt to compile this
code? (Assume that you're using -Wall.
b. Check your answer experimentally.
c. What do you expect splint to report for this code?
d. Check your answer experimentlaly.
e. What value do you expect i to have when you print it out?
f. Check your answer experimentally.
You've learned that the ++ operation increments its parameter.
You've also learned that you can place it before or after a variable.
What's the difference? Let's check.
a. Predict the output of the following chunk of code.
int x = 5;
printf ("x = %d\n", x);
printf ("x++ = %d\n", x++);
printf ("x = %d\n", x);
printf ("++x = %d\n", ++x);
printf ("x = %d\n", x);
b. Check your answer experimentally.
c. Predict the output of the following chunk of code.
int y = 6;
printf ("%d %d %d %d\n", y++, y++, y++, y++);
d. Check your answer experimentally.
e. Discuss the meaning of your output.
Tuesday, 1 February 2011 [Samuel A. Rebelsky]
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2011S/Labs/more-types-lab.html.
Monday, 7 February 2011 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Schedule]
[Piazzza]
-
[Academic Honesty]
[Instructions]
Current:
[Current Outline]
[Current EBoard]
-
[Current Assignment]
[Current Lab]
[Current Reading]
Groupings:
[Assignments]
[Documents]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Readings]
[Reference]
Related Courses:
[CSC195 2003S (Rebelsky)]
[CSC161 2009F (Coahran)]
[CSC161 2010S (Walker)]
[CSC161 2010F (Rebelsky)]
Misc:
[SamR]
[ISO]
[GNU Coding Standards]
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 Mon Feb 7 10:48:21 2011.
The source to the document was last modified on Mon Feb 7 10:46:14 2011.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2011S/Labs/more-types-lab.html.
A PDF version of this document may be found at
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2011S/Labs/type-lab.pdf